Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Why is Scala said to be more functional than Java?  RSS feed

 
Ranch Hand
Posts: 1095
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java one way of functional programming is using Lambda expression where functions are passed as argument in cases where Functional Interfaces are involved.
Why is Scala said to be more functional than java?

thanks
 
Saloon Keeper
Posts: 9997
208
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scala simply has more functional features built right into the language. Among others, some important ones are that it has collections that are evaluated lazily, you can use the apply operator on functions and you can use partial function application.

For example, when you have a function in Java you can only apply it by calling the method that is defined in the functional interface:

In Scala, you can directly apply a function to some arguments by putting the arguments in parentheses after the function name:

In Scala, you can also apply functions partially to get a new function:

In Java, you can't do this without writing utility methods:

These are but a few of the functional features that Scala has and Java doesn't.
 
Monica Shiralkar
Ranch Hand
Posts: 1095
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Also, in the java example the method name (apply) helps understand what it does.
 
Stephan van Hulst
Saloon Keeper
Posts: 9997
208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you get more familiar with functional programming, you will see that words like "apply" are incredibly verbose compared to just using the apply operator.

It's similar to how three.plus(five).times(two) is less readable than (three + five) * two.
 
They weren't very bright, but they were very, very big. Ad contrast:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!