Tab wars revisited (was Re: Python indentation)
geekspeak at hotpop.com
Thu Jul 8 00:16:15 CEST 2004
Mike C. Fletcher wrote:
> Jarek Zgoda wrote:
>> Istvan Albert <ialbert at mailblocks.com> pisze:
>>>> Ambiguity sucks but a SPACE is a SPACE is a SPACE.
>>> Is there a reason why a TAB is not a TAB is not a TAB?
>> Because TAB is TAB and not 8 * SPACE nor 4 * SPACE nor 2 * SPACE. In
>> editor you don't see a TAB, you see 8 * SPACE or 4 * SPACE or 2 * SPACE
>> or any number of spaces you set in your editor options. There's no
>> display character for TAB, it is substituted by SPACES.
>> As you see, TAB is down, while spaces are up. Resistance is futile. You
>> will be assimilated.
> Nope. People have been telling me to use spaces in my Python for
> *years*, and I'm nowhere near assimilated. The number of silly
> occasions where hitting <del> or <backspace> to remove a tab works where
> the editor doesn't pick up an attempt to remove 4-or-so-spaces keeps me
> going back to the simple "a tab is an indent" approach. The simple fact
> ( ;) I know, it's a holy war, there are no facts, but I feel like
> tweaking the spacies) is that having 3 or 4 or 2 or 8 characters
> represent the concept "indentation level" is just silly when you've got
> the single character representation available.
IMHO, it doesn't make that much difference if you use all tabs or you
use all spaces for your indentation if you're the only one that ever
edits the source file. The problem comes in if the two ever get mixed
in the same file, which is particularly problematic if you have more
than one person working on a file or if you share some code as open source.
If you use tabs in your source with a 4-space width and I make a mod to
one of your files when I have my editor configured to insert 4 spaces
for indent, it'll look the same on the screen but Python will get very
unhappy. Because all blocking in Python is based on lines with
identical amounts of indentation, Python has to convert all those tabs
to some amount of spaces in order to calculate indentation. Since
Python has no idea what tab width you have set in your editor, it has to
assume a fixed size for tabs (which, IIRC, is 8 spaces). Because of
this, your 4-space wide tab and my 4 real spaces represent different
indentation levels and the blocking of the code is now hosed.
The advantage of using all spaces is that no matter what editor you load
a source file in or what your tab-width configuration is, it is
guaranteed that a human being and the Python interpreter will both see
the indentation the same way.
More information about the Python-list