Why Tabs Suck

Posted by Andrew on August 05, 2008

I’m quite often receive a puzzled look when I explain to .NET coders that, like Ruby developers and others, I prefer spaces (2 to be precise) over tabs. If you’re already a space aficionado you may go about your business, otherwise read on.

First of all, I don’t have a problem with the tab character per se. My problem is that it’s all too easy to misuse it. Observe:

This code, taken from an open source project that mandates tabs, illustrates the problem - The author has mistakenly applied a liberal sprinkling of spaces in with the tabs:

Of course, the problem manifests itself because my indent level is different to that of the author. And, to be honest, I don’t think I’ve ever seen a tab-indented project that didn’t suffer from this problem.

Spaces, on the other hand, are atomic and consistent - They always render the same way.

So which indent level? Studies have shown that 2 to 4 is the sweet spot:

Although blocking style made no difference, the level of indentation had a significant effect on program comprehension. (2-4 spaces had the highest mean score for program comprehension.) We recommend that a moderate level of indentation be used to increase program comprehension and user satisfaction.

Personally, I prefer 2 spaces because it’s no less readable but uses less horizontal real estate.

kick it on DotNetKicks.com