r/programming • • May 25 '17

Readable Clojure

http://tonsky.me/blog/readable-clojure/
42 Upvotes

35 comments sorted by

View all comments

11

u/maestro2005 May 25 '17

I disagree strongly with wrapping things in redundant some?/none? checks. (when thing ...) is entirely idiomatic and you should get used to reading it.

I agree that sometimes excessive comp/partial usage can be hard to read, but his example is bad:

(map (comp str/capitalize str/trim) strings)

Anyone who calls themselves competent in clojure should easily read this as "capitalize and trim the strings". This is actually a perfect use of comp. The benefit of comp/partial is that you avoid creating a new function, which creates a new reference frame and introduces a variable just to pass it along to another function.

Even as experienced Clojure programmer I haven’t developed a skill to parse such structures easily.

Then you're not really that experienced.

1

u/DasEwigeLicht May 26 '17

(map (comp str/capitalize str/trim) strings)

Does clojure have an equivalent to dash.el's anaphoric functions? In elisp you could write this as (--map (-> it str/trim str/capitalize) strings).

1

u/SimonGray May 26 '17

In clojure, the threading macro is a popular and idiomatic way to do this kind of thing, but - I think - usually with more than two transformations.