Why Tabs Are Superior To Spaces

Once and for all, I have the answer! I've long known and exercised my belief that tabs are (far, far) superior to spaces, but only recently have I gained enlightenment as to exactly why they are superior.

Spaces are "hard coded", while Tabs are "dynamic".

What does that mean, exactly? Every IDE worth a damn allows you to adjust the number of spaces that a tab appears to take up. This is commonly referred to as "tab size" or "tab width". If your team agrees (begrudgingly?) to use spaces, then everyone has the exact same view of the code.

The problem is that people's preferences are different. I might like to use 3 space indents so that things don't start flying off the right side of the screen after just a few levels of nesting, whereas you might like 5+ spaces, to really draw attention to where things nest. There's nothing wrong with either preference. And the beautiful thing is, using Tabs and letting everyone set their own tab width (because one person's tab width has no affect on anyone else's view), everyone gets to see what they want to see.

So there you have it. Tabs win. You're welcome.

in Best Practices | Meta Posted 2011-11-01 09:36

5 responses:

Lola LB
Lola LB 2011-11-01 10:32 AM #
I've had to clean up files full of spaces, converting these to tabs, in the past. Not Pretty.
andy matthews
andy matthews 2011-11-01 10:33 AM #
Not to mention that spaces increase document size. Not a huge deal, but lots of code means lots of "wasted" space.
JayGG
JayGG 2011-11-02 11:42 AM #
Only on the third paragraph I realised what are you talking about LOL.

I have read the title and thought - Is he way out of his rocker?? How come Spaces can be worse than Tabs. You can move your stuff around Spaces as you want to, and you can add spaces if you need to. You can even make your application full screen in its own space, and tabs? they are good in browsers...

Then I reached 3rd paragraph... and facepalmed.
Time for a break, because looks my brain does not process information properly right now.

But you are absolutely right regarding tabs - using spaces to make indents should be a criminal offence...
larry c. lyons
larry c. lyons 2011-11-02 3:07 PM #
Actually its not that all difficult to convert spaces to tabs. In Eclipse I just do a select all, copy then paste in to Notepad++. Then I just do a global search for X spaces and replace that with a tab. Copy it back into Eclipse. Nice tab formatted page.
Adam
Adam 2011-11-02 3:47 PM #
I'm fairly certain that the code formatter in CFBuilder 2 will automatically convert for you, but I'm not sure about that.

Leave a comment:

Leave this field empty: