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

4

u/joequin Feb 22 '15

I think it's extremely readable, because unlike functional languages and newer languages it doesn't encourage the cleverness that often impedes code readability.

3

u/kcuf Feb 22 '15

Layering several abstractions, spread across various files/packages, just to achieve future maintainability impairs readability. Shared mutable state impairs understanding, and thus readability.

2

u/joequin Feb 22 '15

Layering several layers of abstraction and composing several functions both impair readability in the same way (not that much).

2

u/kcuf Feb 22 '15

Ya, I wasn't clear. The issue I was trying to get across is the lack of locality with regards to the control flow that is forced upon the developer because the tools in the language are verbose and spread across several files/packages. Add to that the lack of expressiveness has encouraged the use of heavier frameworks/libraries to lower the boilerplate, but often with the cost of obscuring the flow even more.

1

u/joequin Feb 22 '15

You just have to use the right tool with it. That means a text editor that can jump to definitions. There are a lot of them for free and paid. Then locality doesn't matter a bit.

And really, it doesn't' matter if you know how the called methods work anyway. The whole point of functions and objects is that you trust that they do what they say they do. When they don't and you have to debug, it's not hard to see which methods or functions aren't abiding by their stated functionality, as long as you have a good debugger. Java has good debuggers.

1

u/kcuf Feb 23 '15

Those are fair points that many developers will agree with. I don't like being forced to use a specific editor -- these requirements feel like bandaids to cover the failures of the language to adapt to how people use it. On top of that, strong tooling doesn't resolve the issue completely: stepping through the application can be invaluable, but I like that to be a backup, not something I have to rely on to understand how the application actually works. Compare for example this piece of a simple web app using ring & compojure in clojure:

(defroutes routes
    (context "/api/v1" []
        (GET "/users" request (lookup-users (:params request))
        (GET "/users/:id" [id] (lookup-user id))))

(def app
    (-> routes
         (wrap-authentication auth-config)
         (wrap-with-logger)
         (wrap-json)))

(run-jetty app {:port 3000})

Of course this is contrived, but you can see the flow of the application very easily: routes is just a function that takes a request map, and the -> is a standard clojure macro that will take the value and plug it in to the next function as the first parameter, and repeat. So a request will go through the json middleware, then logger, then authentication, and then to the routes function which will match the path and the method, then a response will be fed back through the middleware in the opposite direction.

1

u/joequin Feb 23 '15

The middleware takes a just as much work to understand as an abstraction using classes.

Clojure also suffers from relatively bad debugging tools. The macro is is useful, but not as useful as a debugger. Clojure also has even less viable editors than Java.

1

u/yogthos Feb 23 '15

Debugging in Clojure works exactly the same way it works in Java with both Eclipse and IntelliJ. Interestingly enough, I practically never find I need to debug Clojure though.

On top of that Clojure has a REPL that's always available and conventionally tightly integrated into development process unlike the debugger in Java.

I'm not sure what you're talking about in regards to editors either. Clojure has had support in Eclipse for years, now it has amazing support in IntelliJ with Cursive and Cursive does a lot of static analysis on code the same way the Java editor does. This means you can do refactoring the same way as in Java, auto imports, mismatched argument highlighting, etc.

1

u/joequin Feb 23 '15

That's good to hear. When I tried looking up debugging, no one had suggestions for debugging except macros. There weren't any debuggers.

1

u/yogthos Feb 23 '15

I find it does quite the opposite. Composing functions declaratively states what's being done without mixing in implementation details.

When I see a functions called filter I have a hint as to the intent of the operation. When I see a loop, then I have to carefully read through it to separate what's being done from how it's done. This takes more effort on my part to divine the purpose of the code in question.

1

u/joequin Feb 23 '15

That's poorly composed code. It should be broken up into private methods.

1

u/yogthos Feb 23 '15

The fundamental problem is that loops mix the intent with the implementation details.

Declarative style separates them making it easier to understand what the purpose of the code is. Chaining functions to transform data does not impair readability the way looping does.

2

u/htuhola Feb 22 '15 edited Feb 22 '15

I remember having heard that kind of argument. Somebody said it about Visual Basic or QBasic. Again, given certain constraints, it's true.

1

u/yogthos Feb 23 '15

Since when is declarative code less readable exactly?

1

u/joequin Feb 23 '15

That's not what I said.

1

u/yogthos Feb 23 '15

Then perhaps you could be a bit more specific about what it is that you mean. My experience is that there's far more cleverness in OO than in FP.

With FP everything is data driven. I have some data and I want to transform it into a different piece of data. I break the transformation into steps and find the functions that do these steps. There's nothing at all clever going on there.

On the other hand, with OO we start creating models of things and that can get pretty clever indeed. You end up with a bunch of state machines each doing something funky inside and you have to figure out how they all interact with one another.