[Tutor] Readabilty vs 80 characters

Prasad, Ramit ramit.prasad at jpmorgan.com
Thu Apr 19 15:47:25 CEST 2012


>      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?
> 
> 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.
> 
> Is there a guideline or convention that pythonistas follow about this
> style case?

It is a guideline, not a rule. Usually your (work) environment or 
common sense trumps the guideline.

On a side note, if you wrap that if statement with a parenthesis 
you can avoid the error prone '\' at the end of each line


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



Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  


More information about the Tutor mailing list