3 ms·
The problem is that when auto formatters completely wreck with the semantics of your code because of a missing or misplaced character. It has actually happened
by awild 5y ago
The problem is that when auto formatters completely wreck with the semantics of your code because of a missing or misplaced character. It has actually happened often and drives me nuts every time.
I prefer to write code the way I want/need then apply a formatter to unify my code with that of myself and colleagues.
- xigoi 5y agoIf a formatter changes the semantics of code, that's a bug in the formatter.
- MauranKilom 5y agoDepends on what the formatter does when the code is syntactically invalid in the first place. It could just error out, but that might be annoying if the error is in an unrelated part of the file. So a formatter might opt to format on a best-effort basis even in the presence of syntax problems, but then there's the risk of creating different semantics than intended (once the syntax problem is fixed).
- xigoi 5y agoEvery formatter I know errors out if the file is syntactically invalid.
- awild 5y agoThis isn't about syntactical errors, per se. One example I can remember was an empty if or for loop body where everything beyond it was raised into its scope. I'm taking about pycharm formatter specifically here. This does also happen with braces sometimes, but this would've simply been a syntax error in most other languages or just pulled up the single next line not the entire following code.
- xigoi 5y agoIf you write something like this: if foo: bar That's a syntax error, and a good formatter won't do anything about it. If PyCharm's formatter changes it, I wouldn't use it.