Whitespace: The Silent Killer

Ever have one of those days where everything you check into source control is wrong?


This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2009/11/whitespace-the-silent-killer.html

Dude, Jeff, calm down… it’s just a bit of space.

$foo =~ s/.*?\s+// if it bothers you that much.

I prefer languages where whitespace doesn’t matter to the compiler - C, Perl, Lisp…

If the problem is the extra bytes sent over the network, perhaps the ASP template engine has an option to strip the whitespaces on the fly ? Another option is compressing the response, I don’t know how to do it in ASP but with servlets is easy to do, and the browser takes care of the unzipping automatically. This is convenient for very heavy pages of course. In any case, I prefer the readability provided by the extra spaces.

Different material. I will try this. Thanks so much :slight_smile:

If that code ends up getting downloaded, like with JavaScript, HTML, or CSS, the extra white space wastes download time, and costs money. I bet the world could save hundreds of dollars by taking out the trailing spaces.

Imagine how it is for those of us who spend a lot of time in Python world, where the whitespace isn’t just an OCD obsession, but can actually modify the functionality of code!

The Delphi IDE has a neat setting that automatically throws away trailing spaces.

“Run your IDE in whitespace-always-visible mode, or toggle it frequently”

A friend of mine calls it “Pac-man mode”. All of a sudden you see all of these little dots that need to be gobbled up…

Python world, where the whitespace isn’t just an OCD obsession, but can actually modify the functionality of code!

But isn’t EOL whitespace irrelevant to Python as well?

@Rizwan : +1 ! We want code to be space sentitive!

Or at least a “Trim Trailing and save” option in Visual Studio as we have on Notepad++

Actually, it should be a feature of the IDE. The solution is just a plugin away :slight_smile:

Just like in Vim : http://vim.wikia.com/wiki/Remove_unwanted_spaces (let the holy wars begin…)

eclipse also has a “remove trailing whitespace” option.

I know exactly what you mean. Carefully crafted source code, nicely tucked away in your repository, and then someone with TextMate comes along and automagically adds random whitespace all over the place. Byebye useful diffs!

You seem like the perfect candidate to start using the Whitespace language.

http://compsoc.dur.ac.uk/whitespace/

Eclipse can format your code and/or remove trailing whitespace on save. I think that’s the optimal solution.

Whitespace.
You can’t see it,
it must not matter.
If it does,
Tool broken.

captcha: Danner peet

OMG! Whitespace! Makefiles just popped in front of my eyes. Tabs and all that.

People who don’t care about whitespace, don’t have to deal with merging code. I make sure everyone I work with has to fix their own whitespace merge conflicts. Sometimes they even learn to set their IDE up correctly.

The next question is; should we extend this to automated code formatting? Personally I am not willing to take that step yet, because I don’t like any automated code formatters, and more importantly all the code I write is formatted correctly. :slight_smile:

Diffing for no reason is a mortal sin.