This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Why is Scala said to be more functional than Java?

 
Ranch Hand
Posts: 1257
6
  • 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: 10669
228
  • 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: 1257
6
  • 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: 10669
228
  • 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.
 
Monica Shiralkar
Ranch Hand
Posts: 1257
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. The examples were quite useful to understand the difference.
 
Marshal
Posts: 65806
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Monica Shiralkar
Ranch Hand
Posts: 1257
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scala programming is more functional than Java. Unlike Java to apply function  we do not require a functional interface to exist. We can apply it directly. Also in Scala we require to write shorter code. Which of these or any other is the primary advantage of Scala?

Thanks
 
Campbell Ritchie
Marshal
Posts: 65806
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What makes you think that a language is or isn't functional because it does or doesN't have a type called function?

I think I had better merge you with your older thre‍ad.
 
Monica Shiralkar
Ranch Hand
Posts: 1257
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java we can do functional programming but not without a functional interface. In Scala there is not such restrictions. We can direclty apply function. This difference is there because functions are not first class citizens in Java.
 
Stephan van Hulst
Saloon Keeper
Posts: 10669
228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely, in Scala when writing a higher order function you must also specify the type of the function it accepts before you can apply it?

Whether a functional type is defined inline or in a separate file hardly decides whether a language is functional.

For me, a language is functional when you can treat the language's notion of a function or method as an entity that you can pass around as if it were a simple value.
 
You've gotta fight it! Don't give in! Read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!