r/programming • • Feb 22 '15

Java Makes Programmers Want To Do Absolutely Anything Else With Their Time

http://www.forbes.com/sites/quora/2015/02/21/java-makes-programmers-want-to-do-absolutely-anything-else-with-their-time/
35 Upvotes

636 comments sorted by

View all comments

140

u/karlhungus Feb 22 '15

I have no love for java.

While it performs pretty well nowadays, it still isn’t competitive with C or C++ and, with a little love, Haskell and OCaml can or will eclipse it in that domain.

I didn't think this was true, i thought it was somewhat close to C (excluding startup).

For real-world production servers, it tends to require a fair amount of JVM tuning.

This is really seems like reaching for something to be a problem that isn't.

because it objectively sucks.

If people can't even define OO, it can't objectively suck. If you were making a pun i forgive you.

culture is one of mediocrity and bad taste, with MetaModelVibratorVisitorFactory

These kinds of strawmen make me feel like "I don't have to read another word this person writes."

61

u/[deleted] Feb 22 '15

These kinds of strawmen make me feel like "I don't have to read another word this person writes."

I agree to an extent - but I do think the Java community overembraces creation of single-purpose objects over just calling functions.

See this example from the Apache HTTP client docs:

HttpPost httpPost = new HttpPost("http://targethost/login");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("username", "vip"));
nvps.add(new BasicNameValuePair("password", "secret"));
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
CloseableHttpResponse response2 = httpclient.execute(httpPost);

First off, it's great that they used an ArrayList<> instead of a NameValueCollection() or something, but wouldn't the code be better like:

HttpPost httpPost = httpclient.post("http://targethost/login");
httpPost.addParam("username", "vip");
httpPost.addParam("password", "secret");
HttpResponse response = httpPost.execute();

That's 33% less written code, with no real minuses other than implementation details are hidden.

It seems very endemic to Java libraries that the API is written to require the full power of the library, rather than being written to be simple to use. In this case, it's written to allow a lot of flexibility in how forms are encoded, in how name-value pairs are constructed, etc., at the cost of needing to build (unnecessary) HttpPost, NameValuePair and UrlEncodedFormEntity objects.

See also: Swing, Apache Lucene, Struts, many other popular frameworks.

28

u/pfitzsimmons Feb 22 '15 edited Feb 22 '15

Some newer libraries are getting better at this. For example, now you can use Unirest for http in java, which is even simpler than your example:

Unirest.post("http://httpbin.org/post")
  .queryString("name", "Mark")
  .field("last", "Polo")
  .asJson()

Also, the new Java RESTful web services API is actually pretty good. I actually like its way of defining endpoints better than how python frameworks like django and flask do it.

But yeah, it really does baffle me how so many java libraries seem to go out of their way to make you use five lines instead of one. Why not add a bunch of helper methods for the most common use-cases? Time adds up when everything you do is twice as verbose as it needs to be.