Re:Better Clojure formatting
by harlanji on Thursday December 06, 2018 @05:33PM
(#18623091)
No mention of cljfmt, which I’ve used for a few years via lein plugin (‘lein cljfmt fix’).
[ Parent
| on HN ]
I think you're missing the point. The point isn't "no tool exists to format my clojure code!" which is obviously wrong. The author is looking to define a standard that is simple enough to define once and be used universally. `cljfmt` is awesome and I use it myself, but it fails on pretty much all of the criteria the author lays out (slow startup time, it is "extensible," formats macros/binding-forms/functions differently, etc).
Honestly, I think this is a bad idea. The way Lisp works, you need to load the code to have a shot at knowing the correct indentation. You can't just do it statically without abandoning the different syntax for function calls vs. block-of-code macros, as the distinction between the two may not be generally apparent until runtime.
That isn't "how lisp works," that's how most people choose to format their lisp code.
And this is the entire point of the article. He discusses this at length: to reach the universality and speed of a `gofmt`-like formatting tool, we would have to give up on the idea that s-expressions should be indented differently based on their content.
Personally I find this a very tempting tradeoff. You may not, but indenting different s-exps in different ways based on their first element is not "correct," it's just... what most people choose to do.
> You may not, but indenting different s-exps in different ways based on their first element is not "correct," it's just... what most people choose to do.
They are not just s-expressions. They are programs. Just like a C code is not a random string, but a program.
It's worth pointing out that this post is in response to the discussion over at clojureverse, which is an effort to come up with an option-free indentation standard similar to gofmt or prettier.
https://clojureverse.org/t/clj-commons-building-a-formatter-...