2005.03.09
Removing White Space from Source Code
by Karel Thönissen

Caffeinated wrote in Joel on Software:
After a brief discussion with the client's Lead Architect ("Every operator will have exactly *one* space before and after..."), I've realized something...
Source code should be devoid of any type of whitespace. No carriage returns, no spaces, no tabs. It should be the job of the IDE to render the source as the developer sees fit.
Immediate benefits include smaller files, easier diffs, and an absence of trivial changes showing up in file compares. Of course, this means that file compare utilities will have to figure how to format and render source code.
Your thoughts?
I replied, after others proposed removal of spaces and using a prettifier purely for display:
I would fire you. No seriously. I do not want half-clever tools to mess with my carefully crafted layout automatically and without my consent.
There is only so much a prettifier can do. There is more spacing, than just the spaces in the left margin. Manual prettifying is essential for good maintainable code, although automatic prettifying can provide the first cut.
Storage overhead is a non-issue. Source code control and file diffing are, but hey, use a tool that removes duplicate spaces before running such tools.
You approached the problem exactly from the wrong end.
Son of Parnas replied:
> I would fire you.
Your carefully crafted code must be really something to ruin someone's life over.
The idea that a program is just data and should be rendered according to a style sheet is an old one and valid one. It just hasn't been terribly practical until lately. I am not a big egoless programming fan, but a little less ego could be useful.
Me:
Style rules, company-wide, and egoless programming all appeal to me. We practice this in our company rigorously. From the source code alone here one cannot see who had written it. Everyone here is convinced that the style rules make sense. They have proven themselves over time, yet were always adapted when necessary.
Only too bad that automatic style sheets do not work. There is too much information in column wise mark-up. In reviews errors are discovered because lack of symmetry is easily spotted. Show me one tool that will take care of horizontal spacing in source code. I am not talking about simple indentation.
Automatic prettifying decreases the readibility of carefully crafted source code. That is any code that meets our style guide, not just my code written to my personal taste. Given this style guide, using a prettifier not only deteriorates code quality it also raises false alarms in source control and diffing. Break these rules too often and you are out.
So someone not agreeing with the style rules should either comply or explain why the other approach is better.
BTW another reason to use spaces in source code, even in places where it is not strictly necessary for the compiler, is that it can facilitate systematic searching with simple tools. Using unnecessary spaces, it is straightforward to search for all occurrences of object 'a' wihout getting too many false alarms.
|