Sorry for resurrecting an old thread, but I was excited to see @didibus mention using commas here. I do exactly this. These days I’m an engineering team of one at CollBox, so I don’t yet know how this will go over with other engineers, but I’ve been test-driving this for a few months now and I’m pretty happy with it.
I actually use commas whenever I want to violate the normal Clojure indentation standards. Typically that comes in three cases:
- The
cond
example described above:
(cond
(extremely-long-condition with some lengthy args)
, :foo
(another-extremely-long-condition here)
, :bar)
But that’s probably my rarest usage of it. More commonly I use this with…
- Datomic queries with multiple
:where
clauses that I want to align, but I like having them indented after the:where
keyword like the rest of the key-value “pairs”:
(datomic.api/q '[:find ?user
:in $ ?email
:where [?user :user/email ?email]
, [?user :user/role :user.role/admin]]
db email)
(And yes, I am aware of the map syntax for q
.)
- Compactly-aligned
let
bindings where I have one or two lengthy names I’m binding and I don’t want to shift all of the values annoyingly far right:
(let [name "Bilbo Baggins"
email "bilbo@shire.org"
confirmed? false
something-annoyingly-long
, 42]
; ...
)
I’m sure somebody will say this is the worst thing ever, but I firmly believe that indentation impacts readability, and while the comma trick isn’t exactly beautiful, it lets me express the patterns in the code that I want a reader to notice, without making me fight my editor’s indentation features, and it calls out the non-standard indentation as being intentional.