Tabs versus Spaces in Source Code

Edward Elliott nobody at 127.0.0.1
Mon May 15 19:07:34 CEST 2006


Harry George wrote:

> This has been discussed repeatedly, and the answer is "If you only
> work alone, never use anyone else's code and no one ever uses your
> codes, then do as you please. 

The answer is "Do what works best for your project".  Smart people can agree
on and use whatever convention they want without trouble.  The key is
consistency.

> Otherwise use tab-is-4-spaces." 

Tab is not 4 spaces.  Tab is 1 level of indentation.  The confusion that
tabs equals some fixed width, or can/should be set to some fixed width, is
the entire problem hampering their use.  It implies that conversion between
tabs and spaces is straightforward when it is not.  They are not comparable
entities.
 
> When you do Agile Programming with people using emacs, vim, nedit,
> xedit, wordpad, eclipse, and who knows what else, the 4-spaces rule is
> necessary for survival.

IOW reward programmers for being sloppy and using poor tools.  Anyone who
programs in wordpad/xedit has far bigger problems than worrying about tabs
vs spaces (as do projects who let people program in wordpad/xedit). 
Editors which are designed for programming handle tabs and spaces cleanly.

> The reason is simple: People get confused, and accidentally get the
> wrong tab indents when they move among editors or among settings on
> the same editor.  

Sounds like PEBCAK to me. :) If everyone uses tabs for indent, then it
doesn't matter if Joe's vim showed them as 3 spaces while Mary's emacs
showed them at 6.  You can't get the 'wrong tab indents' when everything is
a tab indent.  Mixing tabs and spaces is where you get problems.

> In most languages this is an irritation, requiring 
> some cleanup.  In Python it is a disaster requiring re-inventing the
> coded algorithms.

Use the -tt flag to the Python interpreter and you'll catch inconsistencies
immediately.  Voila, no disaster.  Again, you're not complaining about
using tabs, you're complaining about mixing tabs and spaces.  I completely
agree with you that the latter is way too much hassle to even attempt.

All I'm saying is that using tabs on their own is perfectly viable and a bit
cleaner.  I'm not trying to force that preference on anyone else, just get
everyone to recognize that one is just as rational and salubrious as the
other.

-- 
Edward Elliott
UC Berkeley School of Law (Boalt Hall)
complangpython at eddeye dot net



More information about the Python-list mailing list