I agree with the article, too much hyperbole saying everything is wrong with the style guide, first, style is subjective (look at Rich Hickey's Java style 😝), second I'd say the style guide is pretty good as proven by tons of people happily styling their code by its rules.
I guess I never even realized this was the indentation, because I never put the first argument on a newline.
So I'd do something more like:
(func a b
c d)
or
(func a
b
c)
I also don't know who sticks with 80line anymore, you try to aim for that, but there's always places where you go beyond. Most auto-formatter won't truncate things.
I think the only style that I could see making a big claim to fame over the current one is the "indent lists with 2 spaces always no matter what", and align vectors, maps and sets.
I think the simplicity of that alternate style guide for pretty descent overall results visually are appealing in a way where I could be convinced that this could take over as the new norm.
Though I'd actually break that rule and say I'd prefer indent lists with 1 space always, and align the rest.
Because with 1 space, things are always visually aligned at least, I find it more pleasing:
(+ 1
2
3)
See how it looks misaligned?
(+ 1
2
3)
And with only one space it looks better.
This actually makes me wonder.... Maybe just always align everything to the first element, simple, still looks good, super straightforward.
I don't think it's that bad. Might be a little harder to see the demarcation with 1 space I guess is the downside and could be the draw to say lists are 2 spaces.
I've been programming in Lisp since before Clojure existed, so I'm a bit biased and my personal take is - if something ain't broke don't fix it (that's to say that I think traditional Lisp indentation is good enough). I wrote in the past about semantic formatting and my perspective hasn't changed. You'll notice that the style guide acknowledges the alternative style (fixed indentation) as a reasonable option. As for using 1 space indentation everywhere - obviously you can do this, there's just not a lot of precedent for doing so and we optimize for real-world usage. :-)
I started to lean on the align everywhere approach because it works well with parinfer and it's what Replete uses on the mobile Android app. And I've been surprised as I use it how well it works.
But you're right, I haven't tried it on a large code base or day to day. But I'm getting tempted to try it.
I do agree that I don't really have a problem with the current formatting, but if I needed to hand format Clojure code, or when I whiteboard, I see the appeal of that alternate style. And then if you buy into the Go philosophy of consistency, that's probably where I'm curious. Though I also don't know if I like the Go philosophy, why style to your lowest common denominator? If in Emacs with Cider I can get more semantic driven, properly aligned code, why not?
6
u/didibus Nov 02 '21 edited Nov 02 '21
I agree with the article, too much hyperbole saying everything is wrong with the style guide, first, style is subjective (look at Rich Hickey's Java style 😝), second I'd say the style guide is pretty good as proven by tons of people happily styling their code by its rules.
Now on to the bikeshed myself 😁
Interestingly there is an open issue about the 1 vs 2 space alignment from 2016 https://github.com/bbatsov/clojure-style-guide/issues/126
I guess I never even realized this was the indentation, because I never put the first argument on a newline.
So I'd do something more like:
or
I also don't know who sticks with 80line anymore, you try to aim for that, but there's always places where you go beyond. Most auto-formatter won't truncate things.
I think the only style that I could see making a big claim to fame over the current one is the "indent lists with 2 spaces always no matter what", and align vectors, maps and sets.
I think it was described here: https://tonsky.me/blog/clojurefmt/
I think the simplicity of that alternate style guide for pretty descent overall results visually are appealing in a way where I could be convinced that this could take over as the new norm.
Though I'd actually break that rule and say I'd prefer indent lists with 1 space always, and align the rest.
Because with 1 space, things are always visually aligned at least, I find it more pleasing:
See how it looks misaligned?
And with only one space it looks better.
This actually makes me wonder.... Maybe just always align everything to the first element, simple, still looks good, super straightforward.
I don't think it's that bad. Might be a little harder to see the demarcation with 1 space I guess is the downside and could be the draw to say lists are 2 spaces.