PEP 308: A PEP Writer's Experience - PRO

James J. Besemer jb at cascade-sys.com
Mon Feb 10 21:26:17 CET 2003


Roy Smith wrote:

> I'm probably going to hate myself in the morning, but I'm forced to 
> admit that, in some ways, the long-winded way (which I've been 
> advocating) is inferior.
> 
> I'm a fan of refactoring (but not a zealot, in the XP-ish "refactor 
> mercilessly" sense).  It's temping to want to factor the "result =" out 
> of the above and end up with "result = ternary involving x>y, x, and y".  
> There's both a cognitive advantage (you only have to read and understand 
> it once) and a coding advantage (if you only type it once, there's no 
> chance of introducing inconsistancy).

You hit the nail on the head.

As I've argued elsewhere in this thread (and previous ones) THESE are the 
main reasons for PEP 308, not saving keystrokes, per se.

Ironically, they actually go to improved readability by greater specificity 
of intent.  Note the subtle bug below and how it cannot arise if rewritten to 
use cond-expr:

     if condition1:
         if condition2
                 targetVar1 = result1
             else:
                 targetVarl = result2
     else:
         targetVar1 = result3


Regards

--jb

-- 
James J. Besemer		503-280-0838 voice
2727 NE Skidmore St.		503-280-0375 fax
Portland, Oregon 97211-6557	mailto:jb at cascade-sys.com
				http://cascade-sys.com	







More information about the Python-list mailing list