teh bigbro blog(tm)
Bigbro's foray into the scary world of blogging

Mon, 21 Mar 2005

The Tabs Vs Spaces Debate

It reared its ugly head again today - while talking online the great TABs Vs Spaces for the indentation of code debate leapt out and revealed a great chasm between 2 groups of erstwhile friends. While I am mostly ambivalent regarding many of the source code formatting options available to the discerning developer today (cuddled Vs uncuddled else clauses, inline or next-line opening braces, etc.) I just cannot fathom any single reason as to why anyone in their right mind could possibly argue logically that spaces should be used for indenting code... ever... for any purpose whatsoever...
I should have donned my flameproof jacket back there, but hey. :-)
Key to my argument for using tabs rather than spaces, is the fact that it's intuitive to use the TAB key to indent code - so a single press of the TAB key = a single indent. While there is a clarification of meaning required as to what the TAB key actually does Vs what the user sees (See http://www.jwz.org/doc/tabs-vs-spaces.html) it surely makes sense that the tab character gets inserted in the file. This means that the presentation / formatting of the code is slightly seperate from the content of the source code. I, personally, prefer a tabwidth of 3 spaces. It works well for me but I would not even suggest to impose it on anyone else. Others prefer 4 space, some prefer 2, yet others like a different quantity - which leads me to the two key points as to why tabs are clearly better than spaces for indentation of source code:

  1. No knowledge of a code formatting standard needs to be known before starting to type code.
  2. A user can set the tabwidth to whatever they so desire, confident that the code will still be laid out correctly.
  3. There are a couple of fringe benefits of using tabs as well...
  4. Files are smaller - one tab character Vs n space characters
  5. (The very fact that the 'n' varies from person to person and from company source code formatting policy to company policy is key to my argument.)
I shall now contradict my earlier statement in that I have found one valid use for spaces rather than tabs - and that is where absolute code layout must stay static for some reason. The only reason I can think of is for the annual Obfuscated C competition (One example I recall from a good few years back was code formatted in the shape of a flag, that when compiled and run output a flag on the screen.) I think it's safe to assume that if you're at pains to make your code as obscure as possible, consistency and readability will be something you'll strive to avoid, and thus the TABs Vs spaces argument is something that I think I can safely claim doesn't apply. If there are other special cases I haven't thought of, do please let me know.
posted at: 20:49 | path: /rants | permanent link to this entry


copyright © 2005-2008, Gareth Eason