Tuesday, June 4, 2013

You shall not use tabs

There have been many debates whether spaces or tabs are better for indentation to structure code. There are good arguments for both sides but no clear winner, which indicates that in the end it doesn't really matter (The hotter the argument the less the value).

Where everyone agrees is that they should be used consistently and that the layout of code is important. Mixing spaces and tabs will lead to messed up layouts and will cause problems in languages where indentation has meaning, e.g. Python.

I have a slight preference for space over tabs for three reasons:

  • Spaces are absolute while tabs are relative. When switching editors the indentation does not change. The true intent/indentation is preserved.
  • Many IDEs support the automatic conversion from tabs to spaces but usually not the other way around.
  • Spaces constitute the lowest common denominator. Every editor must support spaces. Tabs are optional.

None of the above reasons is especially strong but if it has to be spaces or tabs, I vote for tabs.

ps. For more coding laws see here.