Learning Clojure/Coding Conventions

Because Clojure code is just a bunch of literals, it is hard to read if not indented in a readable style. Well-formatted Clojure looks like this:

The general idea here is that, when spread onto multiple lines, the elements of a list or vector should be indented on the lines below. Notice that the line beginning  is indented in by two spaces under   because the list starting   is a direct element of the list starting. However, below that, the author broke from this rule by choosing to line  with   above instead of two spaces in from. Also note that the vector starting  starts interior to its line, so the two lines below continuing the vector are aligned just right of the opening. The rules are:


 * 1) Indent continuation lines by 2 spaces...
 * 2) Unless there is an opportunity to align opening (, [, or { characters...
 * 3) Or unless continuing an interior literal.

In essence, always indent in underneath the (, [, or { to which an element belongs. Admittedly, this scheme does take some getting used to, both to read and to write.

It's quite typical in Lisp that you end up with many trailing parentheses:

Text editors like Emacs can help you cope with parentheses matching and indentation style.