The Koolaid of Clojure
Been looking at Clojure for a little while without actually learning
it. Now that I've finished a course taught by Martin Ordesky on
Functional Programming in Scala, I think I'm ready to tackle (and
compare) Clojure.
I've already had gallons of the Lisp Koolaid back in college, and for
most of my career, thought its concepts (and even its syntax) to be
better than the languages I used for during my day job.
Infix vs. Prefix
I chuckle how many programmers dismiss Lisp, Scheme and by association,
Clojure, because of code like this:
(+ 1 5 3 7)
Everyone knows it is supposed to be:
1 + 5 + 3 + 7
Infix is nice when writing equations on paper, since you need some
sort of separator between the digits, but most programmers use
prefix notation more than infix. My equation doesn't look odd if
I rewrote it like:
(sum 1 5 3 7)
Note the equivalent code in a C-ancestral language would be:
sum(1, 5, 3, 7)
But the advantage of a Lisp language means that you don't worry about
operator precedence. I know what you're thinking. Of course, Lisp
doesn't care about precedence since it uses parens around
everything.
Guilty as charged, however, the complexity of operator sorting in
Scala could make baby kittens cry. Colons at the end of a function
name, er… operator associates to the right? All that just to
save a few keystrokes, huh?
My point is not to convince to like Lisp-style syntax, but just to
admit that it is ok and not that strange.
Shall we move on and talk about imperative and functional programming?
Tell others about this article: