Tabs-vs-Spaces


nathanieltroutman - Posted on 11 December 2008

So I've run across the issu of tabs vs spaces again and have decided to put in my two cents. A nice overview of the topics is given here, but I disagree with is final conclusion. The topic actually consists of three points:

  1. When reading and writing code, how many columns are indented when changing scope.
  2. When displaying the contents of a file what happens when the the ASCII char #9 is read.
  3. When writing code, what happens when you press the TAB key on the keyboard.

The "religious wars" are fought of point #1 as points #2 and #3 are more technical. I personally believe in the TAB key inserting the tab character (ASCII #9) for formatting code and here is why. If you mix tabs and spaces it can make reading code a nightmare because your tab-width might not be the same as the tab-width the other person used with spaces. Hence, stick to tabs only. And since tab-width, how many columns a tab indents, is a matter of personal preference a tab character indicates this much better in my opinion. The idea is not move in x-number of spaces, but indent because we are changing scope. This is what tab-character signifies, that way when the code is displayed, the exact number of spaces is up the the person viewing it, not the person who wrote it. If I like my tabs at 2-spaces wide and you like yours at 8-spaces then a tab can represent both. This I believe is the correct way to view them, its not a question of formatting but of semantics. A tab means changing scope, not insert spaces. 

As a final plug for tabs, if I'm having to match someone's eight-space code its a pain to use 24-spaces to get indention level of 3. Three tabs is much quicker.

Post new comment

The content of this field is kept private and will not be shown publicly.
By submitting this form, you accept the Mollom privacy policy.