PEP 308: some candidate uses cases from live code

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Tue Feb 11 06:32:35 CET 2003


> From: Andrew Koenig [mailto:ark at research.att.com]
> 
> Tony> With the ?: syntax the rearrangement above becomes:
> 
> Tony> sy = d0.year - (d0.month < 7 ? 1 : 0)
> 
> I'd prefer
> 
>         sy = d0.month < 7? d0.year - 1: d0.year
> 
> despite duplicating d0.year because I would rather duplicate
> d0.year than subtract 0 from it.  But it's not a strong preference.

And I would strongly prefer

    sy = d0.year

    if d0.month < 7:
        sy -= 1

which is extremely easy to read, and fits in my field of vision completely (unlike either of the above alternatives where I have to scan horizontally).

Tim Delaney





More information about the Python-list mailing list