Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

Ben Finney ben+python at benfinney.id.au
Fri Jul 1 21:52:07 EDT 2016


Ben Bacarisse <ben.usenet at bsb.me.uk> writes:

> By replying I'm not accepting the premise -- I have no idea if there
> is widespread fear and suspicion of lambdas among Python users but it
> seems unlikely.

I can testify, as the person who started this thread, that there is no
fear or suspicion of lambda here. I use it quite frequently without
qualm for creating self-explanatory functions that need no name.

Rather, the motivation was that a complex thing, with many moving parts,
has an unexplained implementation: a nested set of functions without
names to explain their part in the pattern.

That these are then immediately bound to a name, to me defeats the
purpose of using lambda in the first place. If you want a named
function, lambda is not the tool to reach for; we have the ‘def’
statement for that.

But by using ‘lambda’ the author avoided one of the more important parts
of publishing the code: making it readable and self-explanatory. If
they'd chosen a name for each function, that would at least have
prompted them to explain what they're doing.

So ‘lambda’ is great, and I use it without worry for creating simple
self-explanatory nameless functions. But it's not the right tool for
this job: This is not self-explanatory, and the component functions
should not be nameless.

-- 
 \       “It is forbidden to steal hotel towels. Please if you are not |
  `\          person to do such is please not to read notice.” —hotel, |
_o__)                                               Kowloon, Hong Kong |
Ben Finney




More information about the Python-list mailing list