6 ms·
There's the language and there's the ecosystem. A lot of negative feelings that still linger are, IMHO, directed more at some of the painful historical aspects
by msluyter 12y ago
There's the language and there's the ecosystem. A lot of negative feelings that still linger are, IMHO, directed more at some of the painful historical aspects of the ecosystem: J2EE XML configuration hell, EJBs, bloated application servers, XML for everything, JAX-WS, SOAP, ant, classloader problems, maven dependency hell, 10 different logging libraries, etc... A lot of this stuff truly sucked.
But I feel things have improved over time. Dropwizard, gradle, embedded jetty, jersey, guava, Spring boot, etc... The trend is towards minimizing configuration and overall, the ecosystem has become somewhat more manageable. I wouldn't necessarily call it pleasant, but it's better.
An as for the language itself, Java8's lambdas + streams provide significant improvements.
Compare this (Java 7):
public static List<Integer> sortDescending(List<Integer> ints) {
ints.sort(new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o1.equals(o2) ? 0 : o1 < o2 ? 1 : -1;
}
});
return ints;
}
to this (Java 8):
public static List<Integer> sortDescending2(List<Integer> ints) {
ints.sort((o1, o2) -> o1.equals(o2) ? 0 : o1 < o2 ? 1 : -1);
return ints;
}
(Example is contrived, since you could use the built in Collections.reverse() to achieve the same result. My main point is that we have eliminated ~4 lines (counting braces) of ceremony.)
All that said, I'd rather be using Clojure.
- blazespin 12y agoI suspect readability isn't a big priority for you. Here's how I'd write this, lambdas or not: public static List<Integer> sortDescending(List<Integer> ints) { ints.sort(new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { if (o1.equals(o2)) { return 0; } else if (o1 < o2) { return 1; } else { return -1; } } }); return ints; } My personal perspective is that your use is a typical abuse which turns simple code into something unreadable and overly complex. This makes code hard to maintain and buggy. Not to mention, it's nigh impossible to step through in a debugger..
- msluyter 12y agoshrug. This seems like a pretty standard use of the ternary operator to me. I mean, just google examples of Comparator, and you'll find tons of examples like this: @Override public int compareTo(Object arg0) { Country country=(Country) arg0; return (this.countryId < country.countryId ) ? -1: (this.countryId > country.countryId ) ? 1:0 ; } (http://www.javacodegeeks.com/2013/03/difference-between-comparator-and-comparable-in-java.html http://www.javacodegeeks.com/2013/03/difference-between-comp...) But that's orthogonal to my point, which is that lambdas offer significant improvements to readability because they remove the irrelevant cruft and simplify the code.
- Igglyboo 12y agoI'd have to agree, the GP is very bloated when a simple ternary will suffice.
- jbergens 12y agoAnd lambdas (or similar) has existed in C#, Python, Scala, Javascript and other languages for years. I still thinks this means that those languages has had large benefits compared to Java (7 and older). Now that Java 8 has lambdas even Java developers can learn to write better and more readable code. I also thinks that Java 8 is good enough for most projects now but Java 7 wasn't. Just my thinking.
- twic 12y agoI'll meet you halfway: ints.sort((o1, o2) -> { if (o1.equals(o2)) { return 0; } else if (o1 < o2) { return 1; } else { return -1; } }); Or may i suggest a version with a guard clause and a simple ternary: ints.sort((o1, o2) -> { if (o1.equals(o2)) return 0; return (o1 < o2) ? 1 : -1; }); There's definitely no need for the 'new Comparator' boilerplate any more. That's not the kind of verbosity that adds clarity; it's just ceremony.
- deleted 12y ago[deleted]
- edwinnathaniel 12y agoKeep in mind that JAX-WS with JAX-B beats other rival libraries in other languages. If your requirement is to be a client that consumes SOAP web service given wsdl, I'd take Java any given day. The wsimport and wsdl tool that JDK provides beat any libraries. Also, JAX-B annotation can serialize and deserialize to JSON given the right provider. That's JSON, XML with POJO with the price of one. Good example of Java ecosystem: build on top of existing one / backward compatible / play nice with others.
- nickbauman 12y agoFalse. If you use a language that's homoiconic (any Lisp), you don't need to serialize anything. The source code of the language is already in its serialzed form. You can't beat the speed of not having to do something in the first place. As an aside, no sane person would write a SOAP webservice today.
- therealidiot 12y agoThis may be true but there are many existing SOAP webservices out there still, and the parent mentioned consuming a SOAP API.
- jtheory 12y agoI wrote a SOAP webservice -- not because I'm insane, but because our business relies on data sent to us. We could certainly tell everyone that they'll need to write code to send us the data we need to be of use to them. Or we could look at the installed systems that hold their data, and see what built-in support those systems have for external integrations. And so: we quickly added a simple SOAP endpoint. About serializing -- I'm potentially missing your point, but "The source code of the language is already in its serialzed form" doesn't seem to make sense. Who serializes source code? Values in data structures need to be transmitted, normally (sometimes in the form of source code -- e.g., JSON) -- homoiconic languages are interesting for other reasons, but not serialization.
- nickbauman 12y ago
- MarkMc 12y agoAnt has a bad reputation? I clearly didn't get the memo - I find Ant to be a great little tool.
- lkesteloot 12y agoI've used Ant, Maven, and Gradle, and Ant is the only one that's never given me a minute's trouble. But it's true that it has a bad reputation. It feels harder to use when everything is working right.
- pjmlp 12y agoAgreed, find errors in Ant scripts is a pleasure compared with piles of Maven plugin errors.
- jimbokun 12y agoSome of us don't care for XML as programming language syntax.
- deleted 12y ago[deleted]
- diltonm 12y agoAgreed, ant is solid, the build system makes sense and is clearly laid out.
- squar1sm 12y agoAnt's one of those "seldom skills". You set it up in the beginning and then tweak a little bit. Yes it works, it's fine. I just find it funny that it hasn't changed or evolved in a long time. I just keep taking my old examples and tweaking them. It's weird.
- nickbauman 12y agoOr in Clojure, it's (sort #(compare %1 %2) coll) To reverse it (sort #(compare %2 %1) coll) Where coll is the collection you want to sort. Same caveat applies with: (reverse coll) Try as I might I can't get Clojure to bench slower than its comparative Java. I see no reason to program in Java anymore wherever possible.
- attheoffice 12y agoJava 8 counterpart to you Clojure variant is actually: coll.sort(comparing(identity(), Integer::compareTo)); Or: coll.sort(reverseOrder())
- nickbauman 12y agoBetter! Still much more complex, though.
- kamaal 12y ago>>Java8's lambdas + streams provide significant improvements. It will take more than a decade before we see any decent adoption of Java 8 in the industry. You are still going to see piles and piles of getters/setters, Enums, your design patterns taken to far extreme. Writing such pointless ceremonial code is the bloodline of Java community. Merely introducing a new version hardly changes anything.
- jerven 12y agoThe community that takes design patterns to far just happens to use Java (1.4 ;( ) if they used a different language they would do the same to that :( Anecdote: I once saw a Perl shop that could have been the worst of Enterprise Java. They where the same because they where ENTERPRISE, they suffered in Perl in the same way the common office programmer suffers in Java.
- diltonm 12y agoI was with you until the Lambda stuff. I find the anonymous class _far_ easier to read and code.
- Roboprog 12y agoLambda expression for comparator can be further shortened (for numeric types, descending): ( o1, o2) -> o2 - o1 No ternaries or else-ifs required. Swap o1 and o2 if you want ascending.
- jbergens 12y agoI think we need something that could be called "The good parts of the Java/Ruby/C#/Javascript/... ecosystem". Showing what tools and libraries are recommended at the moment and how some of them work together. In Javascript the ecosystem is growing almost exponentially which makes it impossible to keep up with everything. In Java and C# there is many old classes still in the libraries and around that most experienced developers avoid. And some trimmings of the ecosystem would probably be useful every 3-5 years or so.