79 chars or more?

Stefan Schwarzer sschwarzer at sschwarzer.net
Tue Aug 17 10:28:02 EDT 2010


Hi Neil,

On 2010-08-17 14:42, Neil Cerutti wrote:
> On 2010-08-17, Michael Torrie <torriem at gmail.com> wrote:
>> In general if I find myself consistently going longer than 75
>> or 80 characters, I need to refactor my code to make it more
>> manageable.  If I have to scroll up five pages to find the
>> beginning of a block, that normally means my code could be
>> simplified and improved.
> 
> Looking through my code, the split-up lines almost always include
> string literals or elimination of meaningless temporary
> variables, e.g.:
> 
>         self.expiration_date = translate_date(find(response,
>             'MPNExpirationDate').text, '%Y-%m-%d', '%m%d%Y')

I'd probably reformat this to

          self.expiration_date = translate_date(
            find(response, 'MPNExpirationDate').text,
            '%Y-%m-%d', '%m%d%Y')

or even

          self.expiration_date = translate_date(
            find(response, 'MPNExpirationDate').text,
            '%Y-%m-%d',
            '%m%d%Y')

for consistency.

This not only limits the width but also makes the nesting of
the calls more visible.

Stefan



More information about the Python-list mailing list