Indentation style...

Thomas Wouters thomas at xs4all.net
Mon May 28 04:35:30 EDT 2001


On Mon, May 28, 2001 at 06:42:08AM +0000, bas.vangils at home.nl wrote:
> Thomas Wouters <thomas at xs4all.net> wrote:
>  * No, no, no! Tabs are 8 spaces. Eight. Spaces. Always. Setting it to anything
>  * else is Lunacy! Sure to screw you over, or at least *someone*, sooner or
>  * later. If you want to re-indent, your editor can re-indent the code in
>  * whatever way you wish, though I would vote against it. 

> I think we disagree.

I'm sure, but we also disagree on how to quote postings ;)

> The trick with a tab is that you don't care / don't know how "big" it is.
> Sure, most editors expand it to eight spaces (unless you tell them
> otherwise). Personally I like tab's to be displayed as three spaces.

Well, the problem with that is that *people* can't see the difference
between a tab and a space, and the way an editor handles it differs not only
between editors and versions of the same editor, but also on the user
preferences. If everyone uses spaces, and all tabs expand to 8 spaces, all
goes well, even if a tab sneaks in.

For instance: say, you are tired, and you accidentily type three spaces
where someone else once used a tab as indentation. The interpreter will
treat a tab as 8 spaces. Always. So, in the best case, it'll run just fine
because you did it consistently within a block. In the second best case,
you'll get a syntax error and you'll be awake enough to realize what the
problem is (don't forget: it's invisible!) and in the worst case, some code
will end up in a different block, without you even realizing it!

Or consider the other way aroud. Someone used 8-spaces instead of a tab
somewhere. You set tabs to 4 spaces. The original code was:

if x:
<  tab  > if y:
<  tab  > <  tab  > return something
<8*space> return something else

And in your version it'll be (as far as you can tell, because the problem is
invisible!):

if x:
    if y:
        return something
        return something else

Using three-space tabs simply shifts the problem to deeper indentation
levels, which are that much harder to figure out.

See-you-on-sunday-ly y'rs,
-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list