Tabs vs Spaces

Ok, this is some serious shit that drives me crazy. The reason why you should never, and I mean never and let me emphasize NEVER in your entire life use tabs for indentation is because:

  • We use spaces in the code to separate words anyways.  Why do you wanna introduce yet another character?
  • Tabs will be displayed differently depending on the editor in question.
  • People are gonna mix tabs and spaces in surprisingly novel (or just plain random) ways which will screw indentation even more than before because it’s harder for editors to figure out the correct indentation in this case.
  • The mixture of tabs and spaces will produce lots of redundant lines in your {SVN / Git / whatever VCS} diffs because developers will (un)intentionally change them which is gonna be a lot of fun during code reviews.
  • Tabs are evil!  They’re evil, evil, evil!  Don’t use ’em! (Except for Makefiles (which as you may suspect are EVIL!))

As a last word, it’s not possible to avoid using spaces for indentation in such scenarios:

<tab><tab><tab>function_call(arg1, arg2, arg3,
<tab><tab><tab>              arg4, arg5, arg6);

Long life to spaces!


  1. says:

    2012-4-8, Sunday at 21:18

    The entire Linux kernel uses Tabs for indentation.
    To find out why, get the source code and read Documentation/CodingStyle.
    It is a very funny and wise piece of literature.

    Your problem is not Tabs for indentation. Your problem is people who’ve never learned how to use a decent text-editor like vi, vi, vi or vi. The trick is this (~/.vimrc):

    set autoindent
    set copyindent
  2. says:

    2012-4-9, Monday at 02:26

    I’ve had a great time reading Documentation/CodingStyle and felt in love with it.

    Using tabs for identation could probably work for me if *all* the editors handled the mixture of tabs and spaces in a unified way and if *every* people *always* cared about using tabs and spaces the right way. Unfortunately, it’s not the case.

    My other gripe is not using curlies for one-liner blocks. It may seem like a good idea first but someone will screw things eventually when extending such a one-liner block and forgetting to add the missing curlies.

    Apart from that this whole guide is pure gold which sould be seen by every programmer. K&R is also my style, by the way.

    PS: I’m not a vi user, but I used to use Emacs. :)

Leave a Reply

Your email address will not be published.