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.

18

u/bcash Feb 22 '15

There are, as other comments have mentioned "better" HTTP libraries that present a much higher-level API. But Apache's HTTP Client has the specific aim of implementing HTTP as it's defined, and designed it's class-structure with that as a goal, allowing the various options to be substituted.

So, of course, form submission will be the most verbose example, as URL-encoding pairs of values is a convention, the mechanics of POST go far beyond that one case (yes, that one case is the most common).

There's nothing wrong with this approach. Indeed it's very valuable for non-trivial circumstances. But if you don't need it, there are other libraries available.

→ More replies (3)