Is there a good comparison between Functional Java and Guava?

前端 未结 3 941
生来不讨喜
生来不讨喜 2020-12-31 09:47

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

3条回答
  •  庸人自扰
    2020-12-31 10:01

    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.

提交回复
热议问题