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

Erik Max Francis max at alcyone.com
Sun Feb 9 22:00:52 CET 2003


John Hazen wrote:

> I want to caution against making the else clause optional, as it blurs
> the
> distinction between the conditional _operator_ and the conditional
> _statement_.

I agree.  Furthermore, explicit is better than implicit -- if you want a
None "default," then write it yourself.  How much extra typing is "else
None"?

> Most of you seem to interpret
> >>> activity = "eating" if hungry
> 
> to mean:
> >>> activity = "eating" if hungry else None
> (obvious default if you know it's conditional _evaluation_)
> 
> But, as a future former perl programmer, to me this means:
> >>> activity = "eating" if hungry else activity
> (default if you think it's conditional _execution_; the variable
> retains its former value.)

Worse than that, to a Perl programmer, it looks like the _statement_:

	if hungry:
	   activity = "eating"

(That is, it has no effect on the creation of activity if hungry is
false.)

Allowing the else clause to be optional just increases confusion for a
tiny benefit in reduced keystrokes.  It isn't worth it.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Life is an effort that deserves a better cause.
\__/ Karl Kraus
    Alcyone Systems / http://www.alcyone.com/
 Alcyone Systems, San Jose, California.




More information about the Python-list mailing list