For review: PEP 308 - If-then-else expression

James J. Besemer jb at cascade-sys.com
Tue Feb 11 05:21:16 CET 2003


Tim Peters wrote:

>>You're pushing this too hard.  Pointing out examples of code
>>that work fine, but wouldn't *if* you changed them, isn't a worthy
>>exercise.
> 
> [James J. Besemer]
> 
>>It does support Andrew's claim that programmers less skilled than you
>>attempting to use the and/or idiom are likely to make a mistake.
> 
> Show me any code you've ever written, and I'll show you how to change it so
> that it no longer works as you intended.  Taking code that works and
> breaking it isn't a worthy exercise.

Some code is more fragile than others.  Talking about how easily it is to get 
wrong IMHO is significant.  Looking at "close calls" seems relevant.

I think part of your objection has to do with the fact that several of the 
examples are code you actually wrote.  Thus you may rightly object to 
Andrew's characterization that they only work "coincidentally," when you 
presumably thought through every nuance and knew for a fact that they were in 
fact 100% correct.  I took his point to mean that ordinary programmers might 
not be as thorough as you and would be more likely to make mistakes trying to 
handle similar work-arounds.

If you still think it's irrelevant, I'm happy to leave it as an honest 
disagreement between two people.

> OTOH, I'm
> at a loss to know where "over half" comes from.  Most examples were right
> regardless of spelling, given what their authors claimed of them.  The
> occasional honest-to-gosh error got repeated endlessly in followup posts,
> though.

It's my recollection of the last 1500 messages that there were numerous posts 
by multiple people submitting various alternative for if/else.  It's my 
recollection that about half of them contained unintended errors that were 
pointed out by Andrew K.  Usually it was that the condition of the test was 
reversed and the expression produced the opposite value from intended.  It's 
possible in my recollection that I counted the same mistake in some 
circumstances more than once but I don't think so because there was a 
distinct complaint from Mr. K. in each case.

It's also my recollection that prior to the PEP-308 discussion the topic 
comes up regularly and as often as not the solution presented gets the test 
backwards.

I think it might be worthwhile to go back and count but I lack the motivation 
to do it.

Anyway, I thought most of us stipulated that the work-around alternate forms 
WERE error prone for non-experts.  Are you saying they aren't?

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