Why Tabs Are Better Than Spaces

I think there is no doubt that readability is in the eye of the beholder. If you are customized with a certain code style, it will take some time before you become comfortable with a new style. The biggest part of this process of acclimatization is played by the indentation. We all know which is the purpose of indentation, right? Increase the readability of code by visually grouping blocks of lines.

Indentation can be obtained with tabs or spaces. Discussions about which one is the best have generated the worst flames in the past, up to the point to be compared to (and often called) "wars of religion".

From the title of this post, you should have understood that I'm on the "tabs side". But it's not (just) a matter of personal preference: there is a really practical reason behind this, especially when you need to look at other people's code.

An Example

Imagine two programmers: Alice and Bob (you don't say?). Alice indentation width is two, Bob uses eight. If both use spaces to indent, the aspect of the code will be the same for both. This means that each one will be comfortable with the code that uses his/her indentation width and will find annoying the other style.

But if they both use tabs instead of spaces, the code automagically adapts itself depending on who is reading it. Bob will create a function with tab width eight and then he send it to Alice. She opens the code with her favorite editor that has tab width two and her eyes don't need to get used to a different indentation style. She is immediately productive and she is not forced to use a style she's not comfortable with.


Less time spent, better understanding and happier programmers. These should be enough to make you prefer tabs. However, of you think there are reasons behind the use of spaces, I'm curious. And now, let the fight begin.

Spaces vs tabs civil war

Image generated with imgflip.

Luca Sommacal

Luca Sommacal

Italian developer (mainly in C for embedded platforms), Linux learner, addicted to rock music, history, science and few other things. Follow me on Twitter

comments powered by Disqus