Indentation style...

Remco Gerlich scarblac at pino.selwerd.nl
Sun May 27 14:16:45 EDT 2001


Ken Peek <Peek at LVCM.comNOSPAM> wrote in comp.lang.python:
> Python allows the use of spaces or tabs (but not both!) to indent with.

It does allow both, and then a tab counts a 8 spaces. Mixing them is not
considered a good idea, though.

> I think
> this was a mistake.  I think tabs should be forced at the beginning of lines,
> and spaces should be forced after the first printable character is typed.

That looks terrible when you print it out, or when you look at it or write
it in email clients like Outlook, or have to place snippets in other
documentation. It's not obvious with Python code printed in books. And too
many editors will just mess it up. It would be incompatible with all the
Python already out there.

I don't use tabs at all. Just use 3 or 4 spaces like the rest of us...

(snip)
> This will allow the programmer to set their editor to display a tab at whatever
> indentation spacing they like, and the original structure (which is part of the
> documentation of the code) is preserved.

It's part of the code itself, not only the documentation. It has semantics.

> Most people that try Python at first hate it's indentation paradigm.

End then they stop hating it after 10 minutes or so. It's not a problem.

> BUT--
> after a while they get used to it, then start liking and appreciating it very
> much.  I think the reason is that on a large project with many programmers, the
> code has a tendency to kind of "look the same"-- making the code written by
> others easier to read and understand.
> 
> Forcing tabs on the beginning of lines, and forcing spaces (for white space)
> after the first printable character (except for null lines and multiline
> strings) would be consistent with the philosophy of forcing "highly readable"
> code to be generated.
> 
> Comments?

Forcing spaces or tabs may make things more consistent, but not more
pragmatic. And that's more important.

Luckily, there is no way that Python will implement this, not without any
obvious benefit and with ten years of Python code out there...

-- 
Remco Gerlich



More information about the Python-list mailing list