Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Why Python style guide (PEP-8) says 4 space indents instead of8 space??? 8 space indents ever ok?? (http://www.velocityreviews.com/forums/t323968-re-why-python-style-guide-pep-8-says-4-space-indents-instead-of8-space-8-space-indents-ever-ok.html)

Ian Bicking 10-22-2003 10:59 PM

Re: Why Python style guide (PEP-8) says 4 space indents instead of8 space??? 8 space indents ever ok??
 
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@colorstudy.com | http://blog.ianbicking.org



Christian Seberino 10-23-2003 06:51 AM

Re: Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??
 
Ian

I thought about your example and adjusted last line to fit in 80 columns...

class Whatever:
def method(self, someArg, someOtherArg):
for smallerPiece in someArg:
if smallerPiece.isValid():
newSmallerPiece =
someOtherArg.doSomethingWith(smallerPiece)


Here is the 4 space indent version:

class Whatever:
def method(self, someArg, someOtherArg):
for smallerPiece in someArg:
if smallerPiece.isValid():
newSmallerPiece = someOtherArg.doSomethingWith(smallerPiece)


Each has trade offs.... I don't like breaking last line into 2 pieces
but at least "class", "def", "for" and "if" don't blend into each
other as easily as in the 2nd example.

I'm not convinced yet of 4 space tabs but your point is well taken.

Thanks,

Chris





Ian Bicking <ianb@colorstudy.com> wrote in message news:<mailman.37.1066863551.702.python-list@python.org>...
> 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 ;).


Steve Lamb 10-23-2003 07:07 AM

Re: Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??
 
On 2003-10-23, Christian Seberino <seberino@spawar.navy.mil> wrote:
> Each has trade offs.... I don't like breaking last line into 2 pieces
> but at least "class", "def", "for" and "if" don't blend into each
> other as easily as in the 2nd example.


They blend in? How so? 8 spaces is way too far for the eyes, or at least
*my* eyes, to skip without causing serious pauses. 2 spaces, while I use it
immensely in my Perl days, is where blending occurs. 4 spaces it's pretty
clear that the next line down is a separate block while not having to jump
partway to Siberia to indicate it. Furthremore at 4 spaces you have a
continuation of the lines above to the lines below in even the shortest of
lines.

if x:
x = y
elsif y:
y = z
else z:
z = x

vs.

if x:
x = y
elsif y:
y = z
else:
z = x

Notice that on the 2nd example the block isn't under the control
statements at all. There's no relation of those blocks to the statements
above it. To me that is the biggest thing. There's separation but not so
much that there isn't flow.

if x:
1234v

else:
1234v

Of course, this is all personal preference. You want 8, have fun. :P

--
Steve C. Lamb | I'm your priest, I'm your shrink, I'm your
PGP Key: 8B6E99C5 | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------


All times are GMT. The time now is 11:29 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57