News for hackers. Stuff that matters.
Re:The hardest program I've ever written (2015) by davemp on Saturday March 05, 2022 @10:06AM (#30568163)
Having a strictly (formatter) enforced style is actually how you allow people the freedom to use their preferred style.

Everyone can just set up a pre-commit hook to automatically format the code back into the official style, then everyone is free to put the codebase back into their preferred style.

Otherwise, if developers reformatted code to their preferred style regularly, it would create massive diffs.

Re:The hardest program I've ever written (2015) by fxtentacle on Saturday March 05, 2022 @10:39AM (#30568416)
I feel like I might have explained that badly. In my suggestion, the source code would be diffed as a machine-readable AST tree. That means all source code reformatting actions which do not change the meaning of the source code also do not appear in the diff.

In this explanation about Go:

https://golangdocs.com/golang-ast-package

the text following "and we get a nice structure" is what the source code management tools would be working on. It's an abstract representation of the source code's meaning, but not tied to how things are formatted or indented.

Re:The hardest program I've ever written (2015) by ameliaquining on Saturday March 05, 2022 @10:57AM (#30568564)
I agree it would (maybe) be better if things had been designed this way from the beginning, but as it is it would be totally incompatible with all existing source code management tools, which is a nonstarter. Even if you can switch to a new editor or IDE, you still have to worry about the GitHub web UI and your error reporting tooling and who even knows what else.
Re:The hardest program I've ever written (2015) by davemp on Sunday March 06, 2022 @12:33AM (#30575287)
> That means all source code reformatting actions which do not change the meaning of the source code also do not appear in the diff.

The method I described does exactly that. Most modern formatting tools parse code into an AST then rewrite it based formatting rules. So as long as you format both files to the same rules before diffing, only AST changes will show up.

Re:The hardest program I've ever written (2015) by rowanG077 on Saturday March 05, 2022 @04:10PM (#30571901)
On paper I like this idea. But I can't shake the feeling that every non-text based format I have ever encountered sucks.
Re:The hardest program I've ever written (2015) by hiccuphippo on Saturday March 05, 2022 @11:18AM (#30568749)
And this is how git works with the different newline styles. It can convert them to a single enforced style on commit and converted back when you pull changes.
Re:The hardest program I've ever written (2015) by delusional on Saturday March 05, 2022 @11:37AM (#30568943)
I've never had that work correctly. Mostly it just gets in the way when the line endings actually matter (because my javascript has to load in IE7).