💾 Archived View for gemini.kaction.cc › log › 2022-09-09.2.gmi captured on 2024-08-31 at 11:46:53. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-02-05)

-=-=-=-=-=-=-

Praising automatic code formatters

I believe Go language was first that came with source formatter built into compiler. Here is how they explain why it is good thing:

  • easier to write: never worry about minor formatting concerns while hacking away,

  • easier to read: when all code looks the same you need not mentally convert
    others' formatting style into something you can understand.

  • easier to maintain: mechanical changes to the source don’t cause unrelated
    changes to the file’s formatting; diffs show only the real changes.

  • uncontroversial: never have a debate about spacing or brace position ever again!

I can't agree more. I am human, don't make me do job of machine. I don't want to read long style guides to figure out where to put spaces or in which order put keys of a dictionaty. I don't want to argue with another human about such trifles.

"go fmt" saves me from all this nonsense. "zig fmt" does the same. "black" is getting traction in Python community, although it is not even "official", so it is not so ubiquitous. One way to convert AST into text, and this conversion is done by machine. Good.

Languages born earlier are not that lucky. C language has at least three different styles, each backed by some prominent authority (GNU, Linux, K&R) and dozens of variations of those. Haskell have at least four different source formatters, some of them have numerous configuration options and neither of them beeing even remotely "official". Nix has three formatters, but at least there are some (quite heated) discussions about blessing one of them.

https://github.com/nixos/nixpkgs/issues/120832

A lot of discussion revolves around question of power, about who, ultimately, will decide what is correct formatting. Honestly, I don't care who is on the throne as long there is a throne, and I don't understand why would anybody care.

Formatting is even less noteworthy if you setup treefmt(1), so reformatting of whole repository is just one command.

https://github.com/numtide/treefmt