-
Notifications
You must be signed in to change notification settings - Fork 18
Clojure style guide
Christopher Small edited this page Jun 17, 2014
·
5 revisions
It would be nice if we could agree on some things regarding coding style for Clojure.
- If
m
is a hash map, use(:key m)
instead of(m :key)
wherever possible. The former will still work ifm
is re-implemented as a record, but not the latter. - Prefer maps over records unless they become preferable for some reason down the road (for performance for instance). Note that while still simple they don't have the same level of structural sharing, so unless you need the performance better to avoid. We may modify this policy if we decide the expressiveness and self-documentation around a particular structure would benefit from being a record, but let's in general err on the side of simplicity for now.
Let's mostly follow from this: https://github.com/bbatsov/clojure-style-guide.
A couple of emphases/tweaks/additions:
- 2 spaces indentation
- If you have to split a s-exp between multiple lines:
- put no more than the function and the first arg on the the first line
- separate line for every other arg
- do not start a lambda on the first line (as second exp-elmt) unless you can finish it on that line
- indent over two spaces, even if your first arg is on the first line (not the suggested, of indenting subsequent args to level of first arg); this one is somewhat softer since it disagrees with the official, but I prefer it...
- Prefer
fn
over#(...)
if you are spanning multiple lines - Strike a compactness/(comment|gitability) balance, and slide on this as fits how often code is worked on
So long and thanks for all the fish.