• FizzyOrange@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    29 days ago

    Yeah he’s dead wrong here. Even clang-format - easily the worst autoformatter I’ve used - is an order of magnitude more tolerable than no auto-formatting.

    Sure it might not always be as good as what a perfectionist human would produce, but it’s sure as hell better than what the average human produces, and it means you don’t have to waste time ranting like this.

      • FizzyOrange@programming.dev
        link
        fedilink
        arrow-up
        0
        ·
        28 days ago

        It’s because it uses a global optimisation algorithm designed to minimize line breaks. In practice that turned out to be not at all what you want.

        Most autoformatters use the Prettier algorithm which is both way simpler and much better. The algorithm is basically “can this AST nodes fit all on one line? If so do that. If not spread its children over multiple lines and recurse into them.”

        It gives way nicer looking, more predictable, and more diff friendly results, even if it might use more lines of code.

        Probably the most common thing is how lists of things like function arguments or arrays are handled when they don’t fit on one line. Prettier will do this:

        auto a = foo(
          X,
          Y,
          Z
        );
        

        But clang format will do something like

        auto a = foo(X, Y,
                     Z);
        

        Basically they optimised for the wrong metric.

        In theory you can configure it to be better but I’ve found that anything that strays too far from the LLVM style is super buggy because the developers aren’t using it, so I wouldn’t recommend changing too much.