r/Clojure • • Jun 06 '20

[BLOGPOST] Idiomatic Clojure: Code Smells

https://bsless.github.io/code-smells/
85 Upvotes

27 comments sorted by

View all comments

2

u/dustyalmond Jun 12 '20 edited Jun 12 '20

zero? and = 0 ... are different in very important ways. First zero? cares about the type. It throws when you give it a non-number other than a nil. It also accepts only one argument and is obviously not transitive because of it. This gets weird when you use clojurescript. In certain recent and only slightly older versions of clojurescript, (zero? 0 1 2) will return true just fine without so much as a warning. In the latest version of cljs, it finally throws an error.

You can use zero? if you keep these things in mind, or you can use = and never have to worry about them.

some-> is probably more of a replacement for when-some than when-let.

I'm also not a fan of the threading rule. In practice it's too strict. Moved from kibit to kondo over it, and also due it flagging places to replace = with zero? incorrectly.