Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a good comparison between Functional Java and Guava?

I'd like to use either Functional Java or Guava (or less likely Scala) in a course I'll be teaching. Although there are lots of functional languages that run on the JVM I'd like to stick to something that looks as much like Java as possible, i.e., something that will be most compatible, conceptually and syntactically, with the functional features expected in Java 8.

It looks like Functional Java and Guava are the best candidates. I haven't been able to find anything comparing them in terms of capabilities, ease of use, conceptual closeness to straight Java, etc. Does anyone know of a good comparison between these libraries?

like image 432
RussAbbott Avatar asked Dec 22 '11 20:12

RussAbbott


1 Answers

Guava's goal is not to provide functional idioms in Java. From the Functional Explained Guava wiki page:

Excessive use of Guava's functional programming idioms can lead to verbose, confusing, unreadable, and inefficient code. These are by far the most easily (and most commonly) abused parts of Guava, and when you go to preposterous lengths to make your code "a one-liner," the Guava team weeps.

Please be sure, when using Guava's functional utilities, that the traditional imperative way of doing things isn't more readable. Try writing it out. Was that so bad? Was that more readable than the preposterously awkward functional approach you were about to try?

Leaning too heavily on functional idioms makes not too much sense up to Java 7 as the overhead is too high (see vertical problem). This will change with Java 8 which will change the way Java libraries and programs are design on the detail level. Things that make sense in Java up to 7 will be discouraged to some extent in Java 8. This will motivate a new edition of Effective Java and a lot of new APIs.

If you're trying to teach functional programming it's probably better to stick to a (more or less) pure functional language. Every language that is a melange (or emulation) of FP and OOP will be a distraction.

like image 67
Thomas Jung Avatar answered Sep 22 '22 22:09

Thomas Jung