308 as a special case of 312 (was: Re: Pep 312 value)

Erik Max Francis max at alcyone.com
Thu Feb 27 23:10:23 EST 2003


jerf at compy.attbi.com wrote:

> It gains you your lazy ternary operator, and is *also* useful in other
> circumstances. The "if" implementation is then merely a special case
> of
> something else that is useful elsewhere.

Yes, but you already have exactly this functionality, with lambda: etc. 
All this proposal suggests is making the `lambda' keyword optional for
zero-argument anonymous functions, or thunks.  This makes code less
readable and more arcane, not more.

> Note, and I can't emphasize this enough, that **every** argument tha
> can
> be brought to bear against 312 applies equally to the ternary
> operator.

No, I don't agree with that at all.  PEP 308 suggests the addition of a
concise short-circuiting conditional operator, where none is presently
available; getting the full functionality of a conditional operator with
presently available Python results in monstrosities like

	(C and [x] or [y])[0]

or

	(C and lambda: x or lambda: y)()

which defeat the whole purpose for wanting the operator in the first
place (conciseness _and_ readability).  PEP 312 simply suggests a
shortcut for 

	lambda: x, 

by making it legal to write it as

	:x

This _is_ purely syntactic sugar, and just strips off perfectly readable
keywords to make things shorter rather than more readable.  (One can
certainly make arguments whether or not they find the use of lambdas
acceptable one way or the other, but when you come across a lambda, you
sure as hell know what you've just stepped into.)

I really fail to see the advantage in removing the one keyword that sets
the code apart ("Watch out, there is a thunk here!")

> I believe there are two importent differences between 308 and 312. One
> is
> that lambda already exists, this is just a special-case respelling of
> it,
> so technically, nothing new.

And that's a really tremendously big difference, quite frankly.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ We're here to preserve democracy, not to practice it.
\__/ Capt. Frank Rasmey
    CSBuddy / http://www.alcyone.com/pyos/csbuddy/
 A Counter-Strike server log file monitor in Python.




More information about the Python-list mailing list