> I do it by hand, which I consider to be a small price for readability boost that big. I hope your autoformatter can live with that.
Cursive's formatter has this option.
> I do it by hand, which I consider to be a small price for readability boost that big. I hope your autoformatter can live with that.
Cursive's formatter has this option.
It also has downsides (overly large diffs if you need to adjust alignment after adding a new binding-with-a-long-name to a let clause).
I also find two empty lines between functions to be too much for my taste.
Lining up columns like this can make you crazy. There's a good example of this earlier on the page:
(ns examples.long-aliases
(:require
[clojure.spec :as spec]
[clojure.test :as test]
[clojure.java.io :as io]
[rum.core :as rum]
[diatomic.api :as diatomic]
[clojure.string :as string]
[cognician.chat.util :as util]
[cognician.chat.server :as server]
;; you can use dots in aliases too
[cognician.chat.server.schema :as server.schema]
[cognician.chat.ui.entries.core :as ui.entries.core]))
Here we have two aligned sections, one above and one below the ;; comment. Why aren't they all aligned to the same column? Apparently it's the ;; comment that says "OK, you can stop worrying about alignment here and start a new alignment section below this line."Now what if we remove the comment?
(ns examples.long-aliases
(:require
[clojure.spec :as spec]
[clojure.test :as test]
[clojure.java.io :as io]
[rum.core :as rum]
[diatomic.api :as diatomic]
[clojure.string :as string]
[cognician.chat.util :as util]
[cognician.chat.server :as server]
[cognician.chat.server.schema :as server.schema]
[cognician.chat.ui.entries.core :as ui.entries.core]))
Well, that won't do. Time to realign everything to keep it clean: (ns examples.long-aliases
(:require
[clojure.spec :as spec]
[clojure.test :as test]
[clojure.java.io :as io]
[rum.core :as rum]
[diatomic.api :as diatomic]
[clojure.string :as string]
[cognician.chat.util :as util]
[cognician.chat.server :as server]
[cognician.chat.server.schema :as server.schema]
[cognician.chat.ui.entries.core :as ui.entries.core]))
Now we see another problem with alignment. The sheer amount of horizontal white space makes it hard to visually match up the first several lines that have much names on the left.And how do we decide what to align and what not to align? We're lining up the :as, but why not the closing brackets too?
(ns examples.long-aliases
(:require
[clojure.spec :as spec ]
[clojure.test :as test ]
[clojure.java.io :as io ]
[rum.core :as rum ]
[diatomic.api :as diatomic ]
[clojure.string :as string ]
[cognician.chat.util :as util ]
[cognician.chat.server :as server ]
[cognician.chat.server.schema :as server.schema ]
[cognician.chat.ui.entries.core :as ui.entries.core]))
Plus, alignment obviously works only in a monspaced font. I like to make my code readable whether someone uses a monospaced or proportional font. If you forgo alignment, code is equally readable in any kind of font.And really is non-aligned code any less readable than the aligned version? It may not be quite as pretty, by some definition of "pretty", but does it really matter? And it has the advantages of not requiring constant fiddling as you add names, not messing up your VCS diffs, and keeping the left and right parts of the :as close together so you can easily match them up visually?
(ns examples.long-aliases
(:require
[clojure.spec :as spec]
[clojure.test :as test]
[clojure.java.io :as io]
[rum.core :as rum]
[diatomic.api :as diatomic]
[clojure.string :as string]
[cognician.chat.util :as util]
[cognician.chat.server :as server]
[cognician.chat.server.schema :as server.schema]
[cognician.chat.ui.entries.core :as ui.entries.core]))Now, I do think this is of rather limited value. So I wouldn't die on this hill. But, column alignment is clearly superior to my subjective eye. It is a shame not everyone has align-regexp.
Definitely subjective, though, I guess.
(ns examples.long-aliases
(:require
[ clojure.spec :as spec ]
[ clojure.test :as test ]
[ clojure.java.io :as io ]
[ rum.core :as rum ]
[ diatomic.api :as diatomic ]
[ clojure.string :as string ]
[ cognician.chat.util :as util ]
[ cognician.chat.server :as server ]
[ cognician.chat.server.schema :as server.schema ]
[cognician.chat.ui.entries.core :as ui.entries.core])) , f l
inside clojure buffers.