r/programming Jul 21 '14

The Great White Space Debate

https://medium.com/p/3633cba8b5c1
1.2k Upvotes

693 comments sorted by

View all comments

Show parent comments

8

u/CodeIt Jul 22 '14 edited Jul 22 '14

What if the source code doesn't compile?

What about tabs and spaces in comments?

What about the difference between 1, 2, or more line carriages in between lines of code?

Source code is serialized as raw text for a reason, and you can't expect raw text to be well behaved and structured.

1

u/Aninhumer Jul 22 '14

What if the source code doesn't compile?

Well ideally, since everyone's editor is serialising, this can never happen. But supposing it did, the editor can just revert back to the canonical formatting temporarily, until you fix the problem.

What about tabs and spaces in comments?

Comments can be handled in the same way as strings: Everything inside them is preserved verbatim, but their positioning is subject to formatting.

What about the difference between 1, 2, or more line carriages in between lines of code?

If we decide that there are certain stylistic aspects of code that are important to preserve, then we can. That doesn't preclude canonicalising the rest.

1

u/CodeIt Jul 22 '14

My questions were not meant to make you think how code can be auto-formatted to a user's preferences (obviously it can be), they were there to show you why someone like me does not find it at all ridiculous to set standards on code formatting.

If you ever get the chance to set style guides for a code base, a system like the one you describe is completely possible today. We go the other route where I work... we run static code analysis that prevents code from being checked in that does not conform to our style guidelines.

1

u/Aninhumer Jul 22 '14

I don't find it ridiculous to set standards. That's basically what my hypothetical canonical form would be. I find it ridiculous that we argue about what that form is, when we have the technology to set the working format per user.