On Thu, 19 Apr 2012, Tino Dai wrote:

Hi!
     I have a question about style. In PEP-8, it says
don't exceed 79 characters, but can this rule ever be
trumped by 
readability?

PEP 8 is style guidelines, not hard and fast rules or they wouls be syntax
errors. But that would just be annoying, so yes, there are cases where you
would want to extend...
Eg.

     
     if someobject.filter(something) \
          .filter(somethingreallyreallyreallyreallylong
== somethingelsereallyreallylong) \
          .filter(othethingreallylongreallyreally ==
ternarythingreallyreallyreallylong) \
          .filter(thirdthingreallylessreallymaybelong ==
thirdotherthingreallylong) \
          .first():
          < do something >

      if someobject.filter(something) \
         
.filter(somethingreallyreallyreallyreallylong == \
               somethingelsereallyreallylong) \
          .filter(othethingreallylongreallyreally == \
              ternarythingreallyreallyreallylong ) \
          .filter(thirdthingreallylessreallymaybelong ==
\
               thirdotherthingreallylong) \
          .first():
          < do something >

    
The first example is more readable to me but violates
the 80 character rule. The second is less readable, but
doesn't violate
the 80 character rule.

This is exactly what the style guide is meant to help. Regardless of which
format you chose here I would tell you that both ways are wrong. The right way
is to fix your algorithm (how you solve the problem) so you don't have to have
such an insane amount of code on one line.

Of course this isn't a hard and fast rule either, but I'd say about 99% of the
time a lot of nesting or chaining indicates a broken flow (even if the logic is
100% accurate).

Is there a guideline or convention that pythonistas
follow about this style case?
Refactor!

hth,
Wayne
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to