Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??
David C. Fox
davidcfox at post.harvard.edu
Wed Oct 22 18:58:45 EDT 2003
Christian Seberino wrote:
> Linux kernel style guide, Guido's C style guide and (I believe) old
> K&R style recommends 8 SPACES for indent.
>
> I finally got convinced of wisdom of 8 space indentation.
>
> Guido also likes 8 space indentation FOR C CODE.
>
> Why style guide (PEP-8) for Python says 4 space indents???
>
> Is breaking rule to use 8 space indents everywhere
> a REALLY bad idea??
>
> I REALLY WANT TO DO MY OPEN SOURCE PYTHON PROJECT
> WITH 8 SPACE IDENTS!!!!
>
> Chris
I don't have an official answer, but here are my guesses:
a)
In C, new lines are generally like any other white space (except within
strings, C++ // comments), so you can easily put new lines in the middle
of an expression.
In Python, newlines are significant, except within lists, tuples, etc.
and a few other cases, so you generally have to escape them with \
within statements. If you use 8-space indents in Python, you very
quickly end up having to escape a lot of new lines, which is annoying.
b)
Unless you have an editor which converts tabs to a fixed number of
spaces, typing 8 spaces is a pain. Even editors which do convert tabs
to spaces may not provide an easy way to un-indent by the same number of
spaces
--------
Of course, both these reasons would imply that 2 spaces was better than
4. Using 4 spaces was probably chosen as a compromise between points a)
and b) and making sure that the indentation level was clearly visible.
David
More information about the Python-list
mailing list