Whitespace: The Silent Killer

That’s not really a hard problem to solve:

  • Mutually accepted coding conventions.
  • Automatic code formatting before committing.
  • Everybody in the team made to setup their IDE right.

Biggest hurdle is getting everybody to accept the coding conventions.

Whitespace definitely is not a non-issue, although trailing whitespace is lot less a problem than wrong indentation.

Im more worried about the horrible spaghetti code you seem to write, what happend to code separation ?

Are you really doing this with code you sell to customers ??

The real thing to blame here is the fact that version control systems are still in the 80’s and match source code as if it were simple text. If Version control systems were not language agnostic, they would never flag trailing whitespaces as diferences, neither putting “{” on the same line vs next line, etc.
One could checkout code and see and edit it with his/her preferences and upon commit it would be converted to an internal representation that abstracted all those differences that did not affect program semantics.

Even if you commit code with lots of spaces in the end (for some weird reason), if those spaces did not affect the program, they would be deleted.

As much as I agree, (if I saw that whitespace, I would almost certainly delete it, even if it was just some irrelevant sample code I was looking at) a commit where the only thing changed was a bunch of whitespace taken out is one of the most ridiculous things ever.

Love it. I recently forced all the programmers on my team to make sure their VS options had tabs NOT SPACES due to the repeated “conflicts” when updating source control. What? the whole file is in conflict?! WTF!?

afw wfwqf wqf
fwqf
wqf
fwq

wfwf
wf
fwq

fw
wqfw
f

fw

I’ve learned over the years to to ignore whitespace, and most other formatting issues foudn in OPC. I’m going to apply that same discipline to ignoring all the incorrect arguments attempting to justify it. Also surprisingly difficult to do.

The real problem here is the use of space characters and not proper tabs. Have you ever gazed upon the horror of source code maintained by two people that both use soft tabs, but have them configured for different widths? Hard tabs, people. Separate the data from the presentation.

Yes you are once we spent hours after site was suddenly crashed just to find out that we had mistakenly put 2 white spaces after PHP closing tag…
But after all we all love web designing and will go on coding…

www.simplify.co.in

John. Judging by your quadruple posting above, I’d say that trailing white space is the least of your problems. For most people (but evidently and surprisingly not everyone) they are a trivial irrelevance that is easily dealt with - if they are even noticed.

Solution: auto-convert the code to a very strict canonical format before commit. There should be one and only one way to represent the same functional code structure.

As long as the white space isn’t case sensitive I will get some sleep at night

Beware not to remove intentional trailing whitespace characters in verbatim string literals (i.e. @“text”).

Example:

More on C#'s verbatim string literal syntax:
http://msdn.microsoft.com/en-us/library/aa691090(VS.71).aspx

This is my take on the maddening side of the smallest mistake in my code:

http://blog.openmountain.com/2009/11/09/the-funny-side-of-web-development-and-multiple-languages/

IN this post I compare Web coding to a Robin Williams routine on golf. Fixing a mistake in some minor part of code is like trying to hit a tiny ball 350 yards into a small hole.

Cheers!

What’s with wall the freaks using spaces instead of tabs? It’s sick I tell you, sick!

In our java builds, we have checkstyle (a style checker, duh) built into our build process to enforce our style standard, and it has rules to check for trailing whitespace. If you don’t fix before checking in… BOOM broken build :smiley:

For once I concur with Jeff: http://dabr.co.uk/status/5387659406

Why are OCD types using spaces over tabs for indentation? Using spaces is a dirty hack.

perhaps i’ve been out of the game too long, what exactly is wrong with this code?

i see the extra whitespace on the foreach line, but does this actually break functionality or make the html render incorrectly?