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

Show parent comments

1

u/CyclonusRIP Feb 22 '15

httpPost.setDoc(xmlDoc); httpPost.addParam("username", "vip");

So what exactly does that mean? The entity of the post can contain many different formats. That's why is makes sense to create the concept of an entity. It's defensive programming. The user cannot use your interface to create some nonsense like I did above.

Also is that addParam a query param or a form param?

I guess maybe that design decision wasn't as dumb as you might think.

You shouldn't really complain too much about consuming the interfaces other people's libraries expose anyways. Your code should always use the ideal interface for your use case. If you are only consuming HTTP client to post forms then write an interface that is extremely geared towards that wraps the HTTP client.

Generally when I use ApacheHttpClient I am consuming a web service so I write an AppClient that maps all the APIs to simple method calls and abstracts the whole idea we're calling out over HTTP. My call would be:

appClient.login(username, password);

If you don't write the AppClient class or it's equivalent then it doesn't really matter what language or library you are using. You are going to have a really difficult time interfacing with a HTTP service.

1

u/[deleted] Feb 22 '15

I never said it's "dumb". I said it includes unnecessary complications. I stand by that.

Regarding your first point, I have no idea what setDoc would do, it doesn't appear in the docs so I can't argue to that.

Regarding your first point and second points, perhaps if it were

httpPost.addFormParam("username", "vip");
httpPost.addQueryParam("redirect", "true");

You shouldn't really complain too much about consuming the interfaces other people's libraries expose anyways

That is literally the most important thing to complain about. If somebody supplies an API with a bad interface that is hard to use, and requires spending hours in the documentation to understand, then that is a bad library. Bad implementations can be fixed easily, bad interfaces less so.

Yes, give me the power to do amazing things, but don't force me to understand the plumbing of your library to use it if I just want the basics. Give me a version that handles the tedium, and also give the version that lets me specify the details. It's not impossible.

1

u/CyclonusRIP Feb 23 '15

I suppose you are right posting an XML doc is probably not something that comes up. Who even uses SOAP? They should have focused more on imitating a browser submitting a form. The Apache HTTP client is basically a Java translation on the HTTP protocol. If you know HTTP well then their approach makes a lot of sense. If you want to write HTTP interactions without knowing HTTP then a library that hides that will only get you so far.

1

u/[deleted] Feb 23 '15

You are getting caught up in my choice of examples, and your sarcasm is not particularly necessary.

(Also, please point me to setDoc in the API docs)