Hacker News new | past | comments | ask | show | jobs | submit login

> the tyranny of linters

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.




Strict adherence to formatting rules can impair readability, yes.

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.


The key point here is that the formatter has to be sufficiently advanced to know to do the right thing the vast majority of the time. Once it gets there, and once you've gotten used to the code it produces, it's better. Note that the "prettier" formatter will do the right thing in JS here, at least with the default config. It will even switch "\"string\"" to '"string"' for you.

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.


> Is someone actually mad prettier is changing their single quotes to double quotes? Are they mad some line is breaking at some word?

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.


If you use linters without auto formatters you are choosing tedium.


Seriously. Python Black is a godsend. I don't have to waste brain cells on formatting minutiae, just right-click and go "format my code, please." It's consistent, it works, and IDGAF about the details.

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.


You know what annoyed me as a C/C++ programmer? People using Microsoft style braces... But OK, if you are using Microsoft-Java, then Microsoft rules apply.

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...


..huh? But either way, should you ever be annoyed by K&R again next time you work with C#, you can trivially change it by setting csharp_new_line_before_open_brace = none in .editorconfig and running dotnet-format tool against solution files.


K&R doesn't just mean the opening brace isn't on its own line, it also means single-line blocks have no braces at all. Always using braces but not putting the opening one on its own line is 1TBS (not the best name, but I don't know what else it's called).


You can omit them too (at the risk of legibility in some conditions).

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);
    }


Yeah, I think OP's point is that nobody should be omitting braces in this day and age. Maybe there's a setting to force the use of braces too.


You dont like kitchens where every cabinet is different slightly different size/color/material?


for some people talking about whether it's best to put a curly brace on its own line or on the same line as an if condition is like talking about which religion is the one true path to paradise...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: