by eddd-ddde · 2y ago · 0 comments
This is a take I don't think I've seen before. Is someone actually mad prettier is changing their single quotes to double quotes? Are they mad some line is breaking at some word?
Certainly I've never been. I use linters / formatters even when I'm working solo because the mere concept of having to think where to break lines is meaningless disruption from the actual goals I have.
If you _really_ want to break a line somewhere, just add a comment in between and your linter will comply.
Before back-tick strings in JS, it was useful to employ both single/double quotes for strings -- you'd use one most of the time, and then if you needed to embed a bunch of that quotation mark in a string literal, you'd switch to the other one.
'my string'
'my other string'
"insert values ('foo', 'bar', 'baaz')"
A formatter with naive "single quotes only" rule would obliterate the last one to: 'insert values (\'foo\', \'bar\', \'baz\')'
unless you remember, before you hit save, to add a directive like: // linter pwease preserve my qwotes
I still use linters and formatters every day, and on balance I think they're good to have, but it's ridiculous to pretend they don't have downsides, or that there isn't room for the occasional dash of human intervention in the automation; hence, the linters which have // linter pwease directives.Linting is a bit of a different beast, because linting includes changes to the code behavior itself, not just syntax. In JS there are so many footguns, that linting can often be pretty involved/strict. I think most of the people who don't like linting in JS either aren't aware of the footguns, or don't do very much code review and haven't worried themselves much with "what sort of bizare and unusual ways can this fail" sort of a thing.
Yes, both of these.
Obviously there are huge benefits to auto-formatting in large teams and popular open source projects, but some people also find benefit in having control of alignment, line breaks, indentation etc.
The only formatting that drives me up the wall is people using K&R braces in C# or Java. It's not 1970 anymore, and we're not all typing on green-screen terminals. It's like people fetishizing vim or emacs over modern IDEs.
AFAIK there is no rule in K&R requiring no braces for single-line blocks. In that situation, braces are optional.
The K&R style was hugely influential on Java and many other languages, it has nothing to do with green-screen terminals (I used those, as well as white and amber), it is just a style. I also moved on from vi, and use IntelliJ and Sublime most of the time.
The only difference between K&R braces and Java braces is that they combine lines on if-else. The Java guys did it because it enabled them to fit more code on to overhead slides. Overhead slide projectors predate green-screen terminals BTW...
All these are configurable (and not enforced by default but you can definitely do so with .editorconfig).
It is also fairly popular in C# to use expression-bodied members where they have just a single expression/statement e.g.
class Test {
public int Property => 42;
public void Method() => Console.WriteLine(42);
}