r/Clojure • • May 24 '17

Readable Clojure

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

31 comments sorted by

View all comments

4

u/schaueho May 26 '17

Overall the advice in this article comes across too strict for me, i.e. its tone. A lot of the article reads to me like "when you want to cater to newbies, avoid the more dense idioms". If the former is your goal, e.g. when you're in a startup situation and want to ensure that you can grow quickly, then I agree it's the right approach and then there is a lot of good advice in the article.

However, I'm reminded of the ?: operator in C. I'm not programming or reading C code alot, so I always have to pay close attention to it when I come across it. But I recognize that the problem there is not so much with the operator then with me being out of touch with a very common idiom in C.

So, I'm not in line with some of the advice. IMHO it's usually way more appropriate to use the common idiom than the proposed alternatives.

E.g. the use of get instead of keywords to access a map. Usually using the keyword communicates the semantic intent a lot better than using get: if you use the latter, your code is focussing more on the data structures in use. The best usecase for get is when you need the third argument.

On avoiding seq?: If the empty? case is the more important one, I'll use empty?. But if it's about the data still being sequential, seq? is just the idiom that was intentionally made up to be used. Learning such idioms is a necessity if you want to master a language.

The proposal to avoid higher-order functions looks completely misguided to me. HOF are one of the great enablers in a Lisp-like language. E.g., comp is of great use when combining transducers.

Which brings me to the threading macros. As a former CL dev, I've been there before. When I started out with Clojure, I saw no benefit in using them. I either wrote my code in a classical function composition style (f (g (h ....))) or used a lot of intermediate variables as in the recommendation. I disliked the threading macros because it's messing around with the fundamental right-to-left evaluation. Today, I know that it can provide a lot more clarity than the introduction of useless intermediate variables. But of course, in some situations using let can still be clearer, for instance when some function in between expects the threaded argument not in the first position.