Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??
Ian Bicking
ianb at colorstudy.com
Wed Oct 22 18:59:08 EDT 2003
On Wednesday, October 22, 2003, at 05:31 PM, 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!!!!
You can, it's just kind of annoying. Typically I work with two indents
at a minimum, because most (of my) code is in a method of a class.
With 8 spaces that's 20% of the space gone. And when using long names,
that means I can end up with word wrapping problems pretty quickly.
Even if I do as little nesting as possible, consider this (quite
reasonable) level of nesting:
class Whatever:
def method(self, someArg, someOtherArg):
for smallerPiece in someArg:
if smallerPiece.isValid():
newSmallerPiece =
someOtherArg.doSomethingWith(smallerPiece)
I hope that turns out okay, since my mail client wrapped it (but then
that was the point ;). I would not consider this level of nesting to
be bad programming, or programming that is in need of refactoring. I
didn't even do tuple unpacking in that assignment...
Maybe I would be more concerned with too much nesting if I was
programming in C. C is more apt to have subtle and dangerous problems,
so you want to avoid even localized complexity. You do a lot more
things in place in C, while Python uses more return values. Because of
exceptions you don't have to use the small chunks of code that C
requires for error detection.
But that's just my own opinion, you can do what you want (just don't
use tabs ;).
--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org
More information about the Python-list
mailing list