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.

0

u/[deleted] Feb 22 '15

There's nothing wrong with this approach.

Isn't there? Why?

What value does this structuring of the library actually add, other than scratching some obsessive itch of the developers?

1

u/bcash Feb 22 '15

Isn't there? Why?

Is there? Why?

What value does this structuring of the library actually add, other than scratching some obsessive itch of the developers?

Right, because it's an all-too-typical standard Java ego-driven bigger-the-better library? Am I right? What would you cite as a good HTTP library in that case?

Meanwhile, back in reality. The httpcomponents project, of which the Apache HTTP Client is a component, is a tried and tested multi-decade project that's more than proven itself. Indeed it's widely used as the basis for these higher-level libraries - the maven central repository finds hundreds of artifacts that cite httpcomponents as a dependency.

And it doesn't just end there, it's used as the basis for HTTP libraries in other JVM languages too. People may think they're escaping Java verbosity writing in Clojure, but if you've made an HTTP request directory or indirectly, in Clojure/Scala/Groovy/etc. you have almost certainly used this library.

And why is it so popular? Because it does everything.

→ More replies (1)