Proposed PEP for a Conditional Expression

Alex Martelli aleaxit at yahoo.com
Sun Sep 9 14:00:05 EDT 2001


Michael Chermside wrote:

[excellent work snipped, as I just want to snipe on one point...]

>              using it may require creating a temporary variable and
>              splitting a formula into two lines, or replacing a lambda
>              expression with a named function.

I consider that replacing lambda forms with named functions, in Python, is 
an *excellent* practice, which should be encouraged by all means necessary. 
 If the lack of a conditional operator does indeed encourage people to 
write more local def's and fewer lambdas, then (to me) that is the "killer 
argument" for not introducing conditional operators.

Maybe (it's been hotly and often debated, but never PEP'd) Python would 
benefit from having some more general way to insert an unnamed code block 
on the fly.  But Python's lambda, as it stands, is so limited and unwieldy 
that encouraging more use of it makes no sense to me.  If we get more 
powerful lambda-like/unnamed-block-like constructs, then the issue may go 
away (I don't think such an introduction would greatly benefit Python, as 
it only introduces more ways to do the same things, and the extra 
complication, I think, outweighs the extra expressiveness -- but I 
understand how somebody coming from Ruby, Smalltalk, or FP languages can 
miss such a feature terribly), and I would then have no substantial 
objection to conditionals (the pro's and con's have been well presented -- 
to me, apart from this lambda-related point, the weighted sum is very 
slightly against introducing conditionals, but not enough to make a big 
difference to me either way).

In PEP terms, I think you could summarize this tirade by 
s/function./function (which some would argue is a good think, given the 
current pitiful state of lambda in Python)./ and have done justice to us 
all adversaries of using Python's current lambdas, while staying 
even-handed (as your whole pre-PEP is so admirably) even on this side issue 
of potential relevance.


Alex




More information about the Python-list mailing list