logoalt Hacker News

o11clast Saturday at 9:14 PM4 repliesview on HN

There are 3 major problems with automated code formatters:

* Handling of multiple newlines to break sections, or none to group related functions (e.g. a getter with a setter). Sometimes it's even best to move functions around for better grouping.

* They don't factor out an expression into a separate variable.

* They destroy `git blame`. This one is avoided if the tooling has always enforced formatting.


Replies

layer8last Saturday at 10:10 PM

Regarding the second one, a formatter shouldn’t be changing the AST. At most inserting parentheses/braces/semicolons for clarity, which doesn’t change the AST structurally (or, depending on one‘s definition of “AST”, doesn’t change it at all).

show 1 reply
dragonwriterlast Saturday at 10:46 PM

> * They don't factor out an expression into a separate variable.

That's...not formatting, and there's probably no good deterministic rule for when to do that, anyhow.

seansselyesterday at 1:05 AM

> They destroy `git blame`

How is this a problem with auto formatters? This is completely on the person/team, not the tool. Even if the repo doesn’t enforce on pre-commit or something, don’t most formatters have the option to only format lines you’ve actually changed?

show 1 reply
zahlmanyesterday at 12:13 AM

> * They don't factor out an expression into a separate variable.

* They implicitly enable people to write deeply nested code that lacks such factoring, without feeling like anything has gone wrong.