66 points · by ooohhhddeeaarrr · 15y ago · 48 comments
One thing I'm not a fan of is the functional stuff. The idea is good, but java is just too verbose. Without real lambdas, like C# has now, it ends up being not so useful.
As others have pointed out, it's not about how much typing you need to do. It's about how quickly you can form, in your head, a conceptual model of what you see on screen and how accurate that model is. While dog-slow IDEs, half-assed Java-style static typing, etc may help you with that, Java's verbosity certainly does not.
Obviously this is a neverending debate.
The fact that you need an IDE to handle all the boilerplate for you should indicate the language is too verbose. In fact I feel like that's what it means for a language to be too verbose.
You should read this: http://steve-yegge.blogspot.com/2007/12/codes-worst-enemy.ht...
List<String> strings = transform(list("hello", "world"),
function(s, s.toUpperCase()));
assertEquals(list("HELLO", "WORLD"), strings);
https://github.com/hraberg/enumerableIt's really difficult to design a good API and Guava didn't get to be like this overnight. It was used internally at google for years then spent years as a pre-1.0 open source project.
On thr other hand, I always have to pause and think a littlr bit longer when using the Guava PreConditions.checkArgument call (even the author of Guava admitted that too)
http://download.oracle.com/javase/7/docs/api/java/util/Objec...
Is there a reason some of this stuff isn't added to the base framework?
- The standard library has to be implemented by all JVM vendors, so adding lots of stuff to it that can also easily be shipped as a library creates a lot of unnecessary effort.
- Changes to the Java standard library have to go through a committee process (JCP); again, it's probably just not worth the effort.
Using static imports to import the newHashMap() method can make the statement even shorter :
final Map<String, Map<String, Integer>> lookup = newHashMap();
This serves to make the code far more readable. Map<String, Map<String, Integer>> lookup = Cf.hashMap();
Which is as short and also doesn't require static imports.Bolts are the state of art FP library for java.
https://bitbucket.org/stepancheg/bolts/src/tip/src/main/java... some examples in tests
No idea about the recent development in fj, they probably made some improvements in the meantime, too.
Java 6 source was introduced without explicit intention and once detected was not addressed. Many companies would not use something whose vital dependencies change on a whim or oversight. A lot of shops are still using Java 5 compilers and have no immediate plan to upgrade. Some cannot upgrade conveniently.
There is an issue to create a Java 5 backport branch when Guava moves to Java 6: http://code.google.com/p/guava-libraries/issues/detail?id=32
> Saw this bug referenced as "a reason not to use Guava."
> Does everyone understand that Guava is still perfectly
> *usable* on JDK 5, it just can't be *built* using JDK 5,
> and that part of the reason for that is *compiler bugs*
> in JDK 5 whose fixes in 6 were never backported?
http://code.google.com/p/guava-libraries/issues/detail?id=36...Guava solves this problem by defining standard Charset constants in com.google.common.base.Charsets ( http://docs.guava-libraries.googlecode.com/git-history/v10.0... ). Java 7 also brings java.nio.charset.StandardCharsets ( http://download.oracle.com/javase/7/docs/api/java/nio/charse... ), but Guava will do for now :)
Immutable collections, e.g. ImmutableMap.of(key, value). These tend to be faster than their mutable counterparts.
MapMaker - really handy for building caches and computing maps. Possibly the most useful thing in guava for simplifying non-trivial Java programs.
Suppliers#memoize - lazy loading without the ugly DCL code that usually goes with it.
Good libraries make a language much more enjoyable to work in. Thanks Google!
I really find this kind of Snark disappointing on HN, and one of the many examples of a decline in the quality of comments that PG has talked about.
Scala is close to Java because it compiles to JVM and you can use Java libraries in scala (so that's not a big deal to switch to it). You can nearly code in scala like in Java with some syntax improvment and in a functional way.
Either you like Java and you don't need Guava, or you want functional programming and other goodness and for that Scala is a better language.