r/Clojure • u/bozhidarb • Nov 02 '21
Everything is Wrong
https://metaredux.com/posts/2021/11/02/everything-is-wrong.html2
u/WalterGR Nov 03 '21
Friendly feedback: on my laptop, everything above the fold is a critique of the blog post in question and reads pretty snarky. Taking the high road in situations like this reads better. :)
1
49
u/weavejester Nov 02 '21
I've worked in Clojure for 11 years now, and 9 of those professionally, and the Clojure Style Guide aligns with my existing expectations and preferences for formatting Clojure code. It's not as if the guide is an invention entirely made up by one person; it's a continuation of existing Lisp and Clojure practices.
When it comes to the 80 character line limit, I still find it preferable even in on larger displays. I can upgrade my hardware, but I can't upgrade what's comfortable to visually process. It's the same reason why newspapers align text in columns, or why book pages are typically taller than they are wide.
20
15
11
u/Akabander Nov 02 '21
I'm sorry that one of the rewards for service is getting the attention of people like that.
9
u/TheLastSock Nov 02 '21 edited Nov 02 '21
Ideally, Programs should be formatted on read, based on the readers personal preference. Where is this most critical? Any source control repo like github, especially when your comparing diffs. The diff should be over programmatic changes. It's damn silly to be wasting time on indentation when there are real problems to be solved.
6
u/NoahTheDuke Nov 02 '21
I too disagree with the 80 char limit and 1-space indentation for functions but you know what I do about it? Change it in my personal projects and then move on with my life. Writing screeds like this is quite unnecessary and caustic.
Thanks for all the hard work you've done, Bozhidar. It's been invaluable to many folks, myself included. I'm sorry this one got to you.
5
u/CoBPEZ Nov 02 '21
You are only âa man who wrote some of the widely used tooling in Clojureâ, how dare you host a crowd sourced style guide?
8
u/InternationalCod3155 Nov 02 '21
The main formatting issue I often see is people aligning the values in maps, it has so many more disadvantages than advantages and although the style guide implies you shouldnât do it, it would be good if it was stated more explicitly. Preferably at the very top. In size 100 font.
Anyway bikeshedding aside, the clojure style guide is a fantastic resource and itâs a shame that itâs not more widely adopted.
4
u/TheLastSock Nov 02 '21 edited Nov 02 '21
What are the disadvantages? Clearly in some cases an outlier key length will force the others to seem odd. But then ideally i could just disable the rule on that map. I haven't come across that case in 5 years so it's fairly rare.
10
u/InternationalCod3155 Nov 02 '21
It creates more conflicts, it makes diffs harder to read, itâs much harder to undo than it is to do in the first place and itâs painful to manage when working in an editor without support for it (like temporary using vim for some quick edits)
Also it really isnt that much easier to read, especially when the keys arenât similar lengths and you have syntax highlighting.
I guess ideally there would be an editor plugin that could visualise the values as aligned but not actually changing the white space
6
Nov 02 '21 edited Nov 02 '21
[removed] â view removed comment
0
Nov 02 '21
[deleted]
1
u/deaddyfreddy Nov 03 '21
and this makes the first 2 slightly easier
I wouldn't be so sure, I've seen a lot of aligned Clojure code which made my eyes bleeding
0
1
u/deaddyfreddy Nov 03 '21
key lengths can differ very much (Especially if you use fully qualified ones), so the potential problems are
the space between a key and a value is so big that it's hard to say if they are on the same line
you can nest more than, say, 3-4 levels, because the line became longer than 100 chars
2
u/bpiel Nov 02 '21
> Everything is wrong all the time. Everyone is wrong all the time.
Yes! If, over the looong run, everything is getting better, then even our best solutions today will be laughably backward in the future. Remembering that can help you stay humble, but also encouraged by the fact the "better" is the best you can do.
2
u/juxtajarred Nov 02 '21
I used the style guide as a base for my last companyâs Clojure style guide and it served us well! I never interpreted it as prescriptive, merely a good place to start that aligns with a lot of the community. Appreciate all youâve done for the Clojure world Bozhidar.
3
u/moxxon Nov 02 '21
The only thing I find "wrong" about the style guide is an 80 character limit... basing modern coding standards on punch card parameters is just silly.
If I'm contributing to a project and their limit is 80 I'll stick to it, but where I'm calling the shots it's somewhere between 100-120.
Overall having a consistent, and reasonable, style guide is incredibly useful, especially when you don't have developers that get anal about it and apply common sense.
1
u/bsless Nov 04 '21
Everyone always talks about the technological considerations of the 80 chars limit and no one talks about the human considerations
The limit should be 60. Humans read short lines. We visually scan paragraphs diagonally.
Look at Tonsky's blog for an example of human-friendly line width
1
u/Eno6ohng Nov 03 '21
I don't think I've ever seen a function call with a line break before the first argument.
As for the 80 width limit, I'd even argue it might be useful to reduce it further (down to 60 or something) to force avoidance of the nesting in favor of flattening refactoring
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.