[Python-ideas] Thoughts on lambda expressions
Ethan Furman
ethan at stoneleaf.us
Wed Mar 2 17:46:02 EST 2016
On 03/02/2016 12:01 PM, Abe Dillon wrote:
> More generally, I think a superior syntax for lambda would be:
>
> (<expression> from <signature>)
>
> The reasons I believe that's a superior syntax are:
>
> a) In the vast majority of use cases for lambda expressions the call
> signature can be easily inferred (like in a key function), so moving it
> after the expression tends to be more readable.
And what does it look like when you have more than one paramater in the
signature and/or something beside simple attribute lookup?
'open': lambda s, cr, uid, rec, ctx: rec['state'] == 'draft',
would instead be:
'open': rec['state'] == 'draft' from (s, cr, uid, rec, ctx),
Ouch. That just went from bad to horrid.
> b) It doesn't use the esoteric name, 'lambda' which causes its own
> readability issues.
On the contrary: 'lambda' lets you know immediately what you're dealing
with. The syntax you are suggesting looks like:
- a (wrong) generator
- taking ... items? ... from some kind of container
To be fair, it looked like an interesting syntax at first glance, but
deeper investigation shows serious drawbacks.
--
~Ethan~
More information about the Python-ideas
mailing list