Whitespace: The Silent Killer

Tabs are nice, but you are never sure are there some spaces or tabs, until you check. Also some tools handle indentation trimming differently than others, which is confusing.

Orā€¦ just take a deep breath, a little yoga, and move on with your life. I know, itā€™s not that easy. But readers, please donā€™t mistake an obsession with whitespace with being a good coder (Jeff, I know you arenā€™t making that argument).

Iā€™ve been coding for years. Wrote a couple of books on the subject. And this has never, ever bothered me. I run the code cleanup plugin in the IDE occasionally and am absolutely fine.

I also dislike terminal whitespaces, but I didnā€™t see the point of saying ā€˜OH MY GOD!ā€™ I tried for a long time to see in which way those spaces would break the code. That would be the only thing that would cause such an outrage.

As I said I also dislike them, and I delete them whenever I get the opportunity, but with source control diffs that can ignore whitespace I donā€™t see it like a big problem and have learned to live with it (especially in a bigger team where some are not that concerned about it).

I think that caring about extra [trailing] whitespace is a little bit OCD-wise. But Iā€™m guilty as charged :stuck_out_tongue:

On the other hand, I find that a little bit contradictory: yes, itā€™s wasted bandwitdth, but so is the one spent on tabbing tags. I suppose the correct OCD solution would be to strip all of the superfluous whitespace.

I guess thatā€™s why my editor has a function to strip white space off the ends of lines. Ultraedit 32. But I donā€™t have a key assignment for it. Not that thereā€™s much that I need to do with that, itā€™s usually the data that I use that on.

GitX (http://gitx.frim.nl/) highlights end-of-line whitespace, so as long as Iā€™m paying attention, I can catch it before itā€™s committed.

At first I honestly did not see what was wrong, but after re-reading and learning of the mistake, I felt dirty, violated and wrong.

Off with the extra spaces.

Check out the built in macro in VS Samples->VSEditor->FixLineEnds - might just be what you are looking for!

Whatā€™s the big deal? It might be a remnant of removed comment.
Completely harmless and irrelevant.

Iā€™m just cheering that you indent with spaces rather than hard tabs. That way when I try to maintain your code, it looks consistent no matter which tools I use.

I couldnā€™t agree more!
What you need in your settings is, replace tabs with spaces, and a tab spacing of 2 or 4 (I used to use 4, but with web pages that can push it too far out).
Tab spacing of 8 is very 1970ā€™s assembler!
Otherwise, the formatting depends on what tools you view the source in, which can seriously mess up the alignment.

I let emacs silently remove trailing whitespace on every save:

(add-hook 'before-save-hook 'delete-trailing-whitespace)

Yes, my diffs are occasionally larger than necessary, but thatā€™s not my fault, itā€™s the guy before me who left all that garbage in the file.

And once I had a multi-line C macro in a header file with CRLF line endings. Compiling on Solaris, only the CR was escaped, leaving LF intact and breaking the macro. Took several pairs of eyes before we figured out why the macro was breaking the compilation in strange ways.

Trailing whitespace breaks our product builds all the time because C compilers donā€™t treat it portably in multiline #defines. Some compilers object to space after the continuation characters ā€˜\ā€™, and others let it fly, allowing a build break on a different platform build. This topic causes a suprising amount of grief. Some people configure their editors to remove it, but since everybody doesnā€™t do so, it can easily muck up version control systems that have merge capability.

ā€œ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!ā€

this is why whitespace is evil.
Think of all the wars that could have been avoided if python didnā€™t require tabs!

Weird how Jeff thinks he speaks for all programmers.

I donā€™t like to be filling my screen with even more characters, but one handy trick is to set the ā€˜visible whitespaceā€™ character color to your background color.

Most of the time itā€™s invisible, but select the text and it pops out.

People, it is time for all of you to discover the Tab-key.

ā€œthis is why whitespace is evil.
Think of all the wars that could have been avoided if python didnā€™t require tabs!ā€

Python doesnā€™t require tabs ā€“ it requires tabs OR spaces. The number of spaces is irrelevant so long as it is consistent.

Python and whitespace is NOT evil because it demands you pay attention to levels of indentation (GOOD) thus the readability of the code, to humans and to the parser, is guaranteed. Debugging is therefore very easy.

Trailing space is irrelevant. Any programming paradigm that still pays attention to space or tabs after a statement (unless of course its quoted) is a ridiculous hack and should be consigned to the dustbin.

I know Iā€™ll get flamed for this, but VB5 and QuickBASIC both remove whitespace at the end of lines AND they also convert tabs to spaces.

Yes, I actually use both languages to do serious work.

Ctrl+A, Ctrl+E+C in Visual Studio takes care of those pesky, non-conforming outsider characters along with other formatting gaucherie.