Hi Dinkar,
thanks for the warm welcome!
Dinkar Chaturvedi wrote:So when compared to other pure functional languages, how do you see Java's functional constructs faring against them?
That's a tricky question... if I say Java's not good for FP, no one will buy my book
Jokes aside, Java's functional support can feel quite constrained or forced compared to a "pure" functional language, but I think that's to be expected in a multi-paradigm language without such support from the ground up.
But for me, that isn't the issue or the eventual deciding factor to use it.
As I see it, the Java team did a fantastic job integrating the possibility of functional programming in a way that works without breaking the language and is quite close to how Java devs would expect it..
Naturally, this is a trade-off and affects how "pure" the functional support or how good the constructs are compared to other languages that don't focus on compatibility, or don't need to integrate it 12 years after the language's inception.
For example, backing each lambda with a concrete type as a functional interface makes them first-class citizens without breaking Java, as there are no dynamic types.
Pre-Java 8 interfaces even become usable for lambdas automagically if the comply with the "single-abstract method" requirement of functional interfaces.
However, enforcing concrete types can create incompatibility between identical lambdas that are represented by different types.
I talk about this in the book, and usually, type inference or bridging the gap with a method reference is enough to make it work.
From a pure FP point of view, that might feel subpar, and it is, but from a Java devs view, you still have access to many of the benefits of FP without needing to go fully functional.
Also, do you think if this limits Java's ability to allow developers to fully realize the potential of achieving the benefits of functional programming?
If a developer only checks out a single language trying to realize the potential of a paradigm's ability, then I'd say yes.
But I wouldn't recommend Java as the language to learn/use if you want to be exposed to the full potential of FP.
Just as you wouldn't start/use F# for being exposed to the full potential of OOP, either.
Sure, you can use either language for both paradigms, but software development is about choosing the right tools for the job.
For me, Java's functional support is a great way to get your feet wet and see the tip of the FP iceberg.
That's why I called my book "A Functional Approach to Java" and not "Functional Programming with Java".
Being able to introduce FP into your Java code base gradually is the real benefit of Java's functional support, in my opinion.