7 ms·
> Align let bindings in two columns > I do it by hand, which I consider to be a small price for readability boost that big. I hope your autoformatter can live
by dantiberian 9y ago
> Align let bindings in two columns
> 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.
- throwanem 9y agoEmacs has align-regexp, if that's of use to anyone in the Clojure world. (It's of extensive use in Emacs!)
- nathell 9y agoIs it just me who doesn't find this to boost readability? 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.
- spinningarrow 9y agoI second this. I actually don't find it improving readability (maybe even worsening it for me) and the unnecessary diff changes aren't useful either.
- Stratoscope 9y agoI'm with you on the column alignment. I don't see how the items in the right column have so much to do with each other that reading down the column is helpful. All that really gets aligned are the opening parentheses, and what's the point of that? 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]))