Hacker News new | past | comments | ask | show | jobs | submit login

As someone who has breathed Clojure for the past three years, I very rarely come across code that is truly difficult to understand. It does tend to be more information-dense than other languages (especially Java) but that just means I only have to understand a couple hundred lines split into 3 files instead of thousands of lines across dozens of files.

That said, there is definitely some nasty Clojure code out there, but I'm not sure that's avoidable in any language. Fortunately, the conventional wisdom to only use macros when necessary has started to catch on and that's made the situation a good deal better.




> As someone who has breathed Clojure for the past three years, I very rarely come across code that is truly difficult to understand.

I'm not really arguing that Clojure code is "truly" difficult to understand, if that is taken to mean reasoning about its performance and effects. Rather, I'm talking about the fact that idiomatic Clojure code encourages writing functions upon functions upon functions, which continually builds up layers of abstraction that inherently make code more and more difficult to read. Example:

console.log("Hiya.");

console.log("How's it ");

console.log("going?");

vs.

printFirstString();

printSecondString();

printThirdString();

function printFirstString() { ...etc }


I don't know anyone who writes code like that. Unnecessary wrapping of functions is an antipattern.

Idomatic Clojure for what you just wrote is:

(println "Hiya.")

(println "How's it ")

(println "going?")

If a Clojureist wanted to get fancy and build an abstraction (as they probably would) they'd probably write a debug function instead of using 'println' directly:

(log/debug "Hiya.")

(log/debug "How's it ")

Which is, granted, an abstraction, but isn't any harder to read.


Or define a function called `printlns`. Then call...

    (printlns "Hiya." "How's it " "going?")


Actually the default `println` already does that. ;)


`println` inserts a space between its arguments. I was showing we could define one that inserts a newline instead.


I could say the same thing about Java. Clojure/Lisp code just tends to have functions that do mostly what their names indicate. Java code tends to be broken up into billions of classes, and understanding an algorithm tends to involve trying to collect together all the pieces of it that are spread out as methods in a bunch of classes.

Take something like code generation from an AST. In Clojure, you might do it in a single file with multimethods. In Java, the code generation algorithm would be spread out over dozens of different AST classes, each with a visitor method.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: