Benefits of removing extra spaces?

I got the habit of removing extra spaces from the source file. In fact, I have my editor to do this automatically. I got this habit using git; it created a habit that I stick to.

My question is that I cannot justify this behavior. I can understand that in some areas, such as web designers, this can affect their final result. However, for the programmer, what do we get from this? Can't we leave him?

+7
standards process conventions whitespace
source share
3 answers

I also like to trim spaces. There are no technical requirements for this, but it has some advantages:

  • Scrolling spaces in many editors is annoying when the cursor changes lines, as you may find yourself in the β€œend white space” of the line when you move from a longer to a shorter line, requiring additional keystrokes to get to the part you want to change
  • This can cause your editor to show a horizontal scrollbar that would otherwise not be needed, which in turn forces you to scroll to the right to make sure that the text is missing.

However, first of all, there is a huge advantage (IMHO) to use sequential formatting throughout the source code (spacing, indentation, brace style ...). This simplifies the reading of the code and avoids the big differences from reformattings (if it is always correctly formatted, no need to reformat).

Therefore, I would recommend allowing formatting to start automatically every time it is saved (or at least for every commit). Thus, the final gap can be excluded as a side effect :-).

+8
source share

You don't say what language you use, but in C-alikes trailing spaces affect macros.

Consider:

#define FNORD() \ something complicated here 

The \ only works if this is the last character in the string --- so a space after it will cause it to break.

+3
source share

Mandatory reference to the post of Jeff Atwood.

Space: The Silent Killer

+1
source share

All Articles