News for hackers. Stuff that matters.
Re:Java for Everything by msluyter on Sunday November 30, 2014 @05:13PM (#8678338)
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.

Re:Java for Everything by edwinnathaniel on Sunday November 30, 2014 @05:49PM (#8678522)
Keep 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.

Re:Java for Everything by nickbauman on Sunday November 30, 2014 @06:18PM (#8678632)
False. 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.
Re:Java for Everything by jtheory on Sunday November 30, 2014 @07:26PM (#8678884)
I 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.

Re:Java for Everything by nickbauman on Sunday November 30, 2014 @09:20PM (#8679184)
So you're consuming data of an existing (legacy) SOAP service? Or complying with exisiting clients of a (legacy) SOAP service? That's not the same as writing a new SOAP service.

If the language you're using is already expressed in a form that does not need serialization, then you don't have to serialize it. This is the very essence of languages that are homoiconic. Perhaps you should familiarize yourself with that before down-voting what I have to say about it.

Re:Java for Everything by jtheory on Monday December 01, 2014 @07:51PM (#8685083)
> So you're consuming data of an existing (legacy) SOAP service? Or complying with existing clients of a (legacy) SOAP service? That's not the same as writing a new SOAP service.

Neither; we're accommodating large, complex systems that only have a few options for "send selected data elsewhere". "Web services" (meaning SOAP) tends to be on that list, plus often other options that are completely unacceptable like "FTP".

> If the language you're using is already expressed in a form that does not need serialization, then you don't have to serialize it. This is the very essence of languages that are homoiconic. Perhaps you should familiarize yourself with that before down-voting what I have to say about it.

I'm someone who responded to you; I didn't downvote anything. I can try again: I use serialization all the time, to convert in-memory data structures into something I can send over a connection (or to disk, etc.), then to reconstitute them back into in-memory data structures on the other end. So I don't yet see how homoiconic languages play into serialization.

Re:Java for Everything by coldtea on Sunday November 30, 2014 @10:06PM (#8679309)
>If the language you're using is already expressed in a form that does not need serialization, then you don't have to serialize it.

Yeah. If only that language and "not needing serialization" code format didn't have 200 other problems, like NONE of the major services accepting it, lack of tooling, a sorry state of an ecosystem, difficulty of finding programmers and/or jobs, etc...

Re:Java for Everything by jerven on Monday December 01, 2014 @10:00AM (#8681316)
And the simple fact that taking code provided by a remote service and just using it as is just handing the keys of your server over.

LISP homoicity is nice but its a bad, bad idea to accept LISP code over the network from any client. Documented dataformats that are not executable are enough of a security risk that sending an executable around is not a great idea.

(Should have been attached to grandparent, as I agree with parent)

Re:Java for Everything by nickbauman on Monday December 01, 2014 @11:47AM (#8682037)
You really don't get it do you. An s-expression doesn't have to be evaled to be read. I just keep getting downvoted here. It's like offering a machine gun to a caveman and getting clubbed to death with it.
Re:Java for Everything by coldtea on Monday December 01, 2014 @03:32PM (#8683581)
>An s-expression doesn't have to be evaled to be read.

Yeah, so you get a serialization format that's the same as your code. Big deal. And you have to live with your code having the same look as a serialization format. Even McCarthy wanted to give Lisp a proper syntax.

>It's like offering a machine gun to a caveman and getting clubbed to death with it.

More like it's coming to Paul Graham's house to tell him all about this new wonderful Lisp thing thing you've discovered. I mean, this is HN, what makes you think those that answered you don't already know and/or use Lisp and its homoiconicity properties?

Being used as a serialization format is perhaps the least interesting and useful property of Lisp code.

Re:Java for Everything by nickbauman on Tuesday December 09, 2014 @10:02PM (#8727451)
> Yeah, so you get a serialization format that's the same as your code. Big deal.

Oh, but it is! Making a massive compute grid can be done with just a few lines of code if your language is homoiconic. If you have to come up with a protocol and a data transfer format, well you have some work to do then.

Re:Java for Everything by jtheory on Monday December 01, 2014 @08:04PM (#8685115)
Okay, this suggests I'm not confused; there's just no argument given.

> Yeah, so you get a serialization format that's the same as your code. Big deal.

There's no reason this would be automatically a "good thing" -- a serialization format that is also valid source code -- it's just a thing. It's good to have a clean path from data structure to serialized data and back again; but if the obvious way to re-create the data structure (exec the code) has a huge security flaw built into it, that's no longer a clean path.

Human-readable serialized formats are nice; but guidelines on "readable" for a data structure vs. "readable" for full-power source code are not the same -- and "compact" is also strongly good for serialization formats, but not nearly so important for source code.

Re:Java for Everything by therealidiot on Sunday November 30, 2014 @06:35PM (#8678683)
This may be true but there are many existing SOAP webservices out there still, and the parent mentioned consuming a SOAP API.
Re:Java for Everything by terryf on Monday December 01, 2014 @05:44AM (#8680344)
SOAP certainly sucks, but regarding your comment on using lisp as the transfer protocol is a bad idea. Data transfer protocols must be verifiable - you should basically be able to write a piece of code that parses the data input and verifies that it will not do something bad if deserialized. Given that as far as I know, Lisp is turing-complete, this task is impossible. Therefore, Lisp, while being a nice programming language, is a very bad wire protocol.
Re:Java for Everything by davexunit on Monday December 01, 2014 @08:14AM (#8680753)
Reading an sexp isn't the same as evaling it. Just read it and manipulate the resulting tree. Lisps have templating, marshalling, and unmarshalling built-in.
Re:Java for Everything by jerluc on Monday December 01, 2014 @04:07AM (#8680091)
You've clearly never tried to implement a REST API using any flavor of Lisp before. Guess what: most clients of web services understand JSON and XML, not S-expressions.
Re:Java for Everything by nickbauman on Sunday November 30, 2014 @09:38PM (#8679225)
Or 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.

Re:Java for Everything by attheoffice on Monday December 01, 2014 @03:05AM (#8679957)
Java 8 counterpart to you Clojure variant is actually:

coll.sort(comparing(identity(), Integer::compareTo));

Or:

coll.sort(reverseOrder())

Re:Java for Everything by nickbauman on Monday December 01, 2014 @11:45AM (#8682008)
Better! Still much more complex, though.
Re:Java for Everything by jbergens on Tuesday December 02, 2014 @06:55AM (#8686679)
I 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.

Re:Java for Everything by blazespin on Sunday November 30, 2014 @05:15PM (#8678387)
I 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..
Re:Java for Everything by twic on Sunday November 30, 2014 @06:23PM (#8678645)
I'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.
Re:Java for Everything by msluyter on Sunday November 30, 2014 @05:44PM (#8678499)
shrug. 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-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.

Re:Java for Everything by jbergens on Tuesday December 02, 2014 @06:31AM (#8686612)
And 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.
Re:Java for Everything by Igglyboo on Sunday November 30, 2014 @06:34PM (#8678680)
I'd have to agree, the GP is very bloated when a simple ternary will suffice.
Re:Java for Everything by x0x0 on Sunday November 30, 2014 @06:41PM (#8678701)
one line is way more readable than 7 lines taking up valuable vertical and brain space

it could also be accomplished with

    return -1 * o1.compareTo(o2);
Re:Java for Everything by adiM on Sunday November 30, 2014 @06:49PM (#8678733)
Why not:

    return o2.compareTo(o1);
Re:Java for Everything by x0x0 on Sunday November 30, 2014 @07:58PM (#8678969)
because the o2 vs o1 is easy to miss, while the -1 makes it obvious i'm intentionally reversing. my .02
Re:Java for Everything by fyolnish on Sunday November 30, 2014 @08:49PM (#8679105)
Not if you give them more descriptive names
Re:Java for Everything by cdman on Monday December 01, 2014 @02:46AM (#8679917)
No, you can't. In particular -1 * Integer.MIN_VALUE == Integer.MIN_VALUE.
Re:Java for Everything by organsnyder on Friday December 05, 2014 @03:36PM (#8706745)
That would probably never matter in practice, though—I've rarely seen compareTo() return anything other than -1, 0, or 1; certainly never anything approaching MAX/MIN_VALUE. Still, bravo for considering all of the edge cases.
Re:Java for Everything by MarkMc on Sunday November 30, 2014 @07:03PM (#8678796)
Ant has a bad reputation? I clearly didn't get the memo - I find Ant to be a great little tool.
Re:Java for Everything by jimbokun on Sunday November 30, 2014 @07:50PM (#8678955)
Some of us don't care for XML as programming language syntax.
Re:Java for Everything by lkesteloot on Sunday November 30, 2014 @07:14PM (#8678838)
I'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.
Re:Java for Everything by pjmlp on Monday December 01, 2014 @04:00AM (#8680080)
Agreed, find errors in Ant scripts is a pleasure compared with piles of Maven plugin errors.
Re:Java for Everything by squar1sm on Tuesday December 02, 2014 @03:20AM (#8686218)
Ant'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.
Re:Java for Everything by diltonm on Monday December 01, 2014 @12:34AM (#8679678)
Agreed, ant is solid, the build system makes sense and is clearly laid out.
Re:Java for Everything by Roboprog on Monday December 01, 2014 @02:59AM (#8679948)
Lambda 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.

Re:Java for Everything by kamaal on Sunday November 30, 2014 @10:23PM (#8679352)
>>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.

Re:Java for Everything by jerven on Monday December 01, 2014 @10:13AM (#8681409)
The 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.

Re:Java for Everything by diltonm on Monday December 01, 2014 @12:10AM (#8679611)
I was with you until the Lambda stuff. I find the anonymous class _far_ easier to read and code.