Software Development

Why Tabs VS Spaces Debate is Pointless

The infamous “tabs vs spaces” debate is as old as the internet itself. It often occurs between groups of polarized developers violently defending their own side. Stack Overflow even made an analysis of their Developer Survey and determined that developers who use spaces earn more. (CDNIC)

Silicon Valley made a great scene about this infamous debate which will really illustrate my point going forward.

What’s this whole thing even about?

When this debate gets sparked in some developer dense groups it is often not specified what people are even debating about. There are two kinds of ways to think about it:

  • Pressing the SPACEBAR key or pressing the TAB key to indent code
  • Using multiple SPACE characters or a single TAB character to indent code

I think this loose specification is the spark plug to every debate. Pressing a key four times, instead of once, is insane in most developers minds. We are all lazy/efficient and this creates the dedicated TAB group. However, the TAB character has some considerations on how it is displayed on various IDEs and this creates the dedicated SPACE group. And then there are the lunatics that just prefer to press one key multiple times for a simple task – I have no explanation for those.

This starts the flame war, each side has a large logical reason in their head for why they are right and can’t imagine someone would think otherwise. But, apart from the lunatics, both are right, they just answer a different part of the debate.

So let’s be reasonable. We developers are highly logical beings after all.


The Key Pressing Debate

Let’s first discuss the “which physical key are you pressing” debate. This is separate from the other part of the debate since all IDEs have an option of you choosing what does your TAB key do. Does it insert X spaces, or does it insert a single TAB character?

I think a reasonable answer here is clear: Why would you want to press the SPACEBAR key X times if you can press the TAB key once. Unless you have a fetish for slamming your keyboard and it helps you relieve stress, you will probably press the TAB key.


The Character Debate

This part of the argument is sometimes considered the tricky one.

The TAB character takes X times (X being the number of spaces you would use) less space on the disk. It is considered a single character that is just wider than others. However, because of this, different environments and machines will display this character differently which means your code will look different to different people.

The SPACE character does not have this problem, it will look the same on every single machine, but will take up more memory for the source code. We do indent stuff pretty often when developing software so the memory difference can really add up.

What to pick?

Both sides have a pretty logical reason behind their choice. But does it really matter? Do you think the environment difference is such a huge problem? Each developer can choose how large their indentation space will be. Does the memory difference make a difference? Yes, but we live in the age where memory is really cheap and a couple of spared megabytes aren’t really a big deal.

So who cares which is better? The most important thing is that you pick a side and you and your team use it consistently across the project. There is nothing worse than mixing SPACES and TABS in a single file. That WILL cause serious maintainability issues. Picking a side and sticking to it WON’T.