For those of you who don’t know me - I’m the author of CIDER, the editor of the Community Clojure Style, and in the Ruby community I’ve spent years working on a formatter and linter for Ruby code (RuboCop) and a Ruby style guide that goes with it.
I think all of this gives me a somewhat unique perspective, as I’m both really passionate about setting up (community) standards and I’ve also experienced how painful all of this can be in practice.
I’m a couple of weeks late to the party, but here are my thoughts…
On the original proposal
I agree that ideally the tool should have no configuration options, but I doubt that’s feasible in practice. When I started work on RuboCop many years ago, it wasn’t configurable and many people were outraged by this. The Ruby community was 15 years old at the time, many formatting patterns existed and very few people cared about global code consistency - most cared about getting consistency in their projects, and of course - with their own style preferences. Luckily for us Lisp’s semantics are much simpler than Ruby’s. Making RuboCop configurable was instrumental to its wide adoption in the Ruby community - we never got complete alignment in the style department, but we got some alignment and this definitely beats none. I know some people are still trying and maybe they’ll succeed at some point, but I lost my desire to participate actively in this, as I’m tired of endless debate over trivial matters.
I think that for the proposed formatter tool to be useful in editors it should certainly be able to operate on lines (and groups of lines), as reformatting the whole files all the time is somewhat annoying for users and not always an option in the first place. That’s probably the biggest reason why most editors have their own indentation engines - they give them the most flexibility with respect to whether you want to reformat everything, just a few lines, etc.
Some people might think that’s not a big concern, but few established projects would accept global changes to indentation and formatting just for the sake of uniformity. Clojure is well-known to be one of them.
I guess for editors a great “API” would be - you send a filename and a range of lines (or characters if you want to be extra granular) and you get their formatted version. If it’s configurable it might be nice if editors can override some of its configuration options (prettier style).
I’m an old-time Lisper and the proposal definitely made me grind my teeth. I understand just as well as everybody else that this is the simplest (and the only way without some extra formatting specs) way to achieve uniformity, but I think the price we’ll pay for this is
“Special” indentation rules usually exist to related “special” semantics. Once you put everything under the same denominator you’re in effect saying that the semantics don’t really matter, which is always debatable. I might expand on this in a separate blog post if I find the inspiration to write one.
I don’t agree there are some rules in existing standards that probably can be simplified, but overall similar constructs have reasonably similar formatting rules and the only real problem is relaying formatters those semantics.
The approach of metadata has always been appealing to me, because:
- it’s self-documenting
- it’s easy to extract this info when doing static analysis
- you have the info at your disposal when doing typically REPL-driven development (as CIDER does it)
It’s also something that Common Lisp and Emacs Lisp have proven to work well - but there we have universal consensus about the metadata and tools that understand it.
I think that adopting an universal formatter/code style 10 years into the existence of a language is unlikely to (fully) succeed if it’s not driven from the top. There will always be strong opposition to whatever we decide, as people have built strong preferences at this point and they’ll need extremely compelling arguments to change them. Changes is hard, and no one really wants to deal with it, especially if they don’t have to.
gofmt succeeded mostly because it was pushed from the top, pushed from the start and everyone was expected to use it. I’m reasonably sure this ship has failed for Clojure, just as it has sailed for Ruby. I don’t know how successful the similar projects for other languages are. I know only that Prettier is quite successful, but it’s also configurable to some extent and it didn’t really propose anything novel in terms of formatting.
That’s why I think that the only way for a tool to gain much traction would be if it’s aiming to enforce something relatively close to what people are doing currently.
I think a formatting tool that can be used from editors would be quite useful, so I’m looking forward to hearing someone create one, although if we set on a simplistic indentation scheme obviously it renders much of the need for such tool redundant, as any editor can trivially implement this (Emacs/cloure-mode has been supporting this “consistent” indentation for years now).
I think we should also set our expectations accordingly about what can be achieved in a mature community - a common formatter would probably have some uptake (as proven by cljfmt), but it won’t be adopted by everyone (also proven by cljfmt).