Is this a good use for lambda
Walter S. Leipold
leipoldw at ace-net.com
Sun Dec 19 14:38:28 EST 2004
Steven Bethard wrote:
> Charlie Taylor wrote:
>>I have tried using named functions instead of using lambda functions,
>>however, I always end up with a convoluted, hard to follow mess.
> ...
> Well, I think the jury could still be out on which version is more
> readable, but I don't understand the comment "I have tried using
> named functions instead of using lambda functions, however, I
> always end up with a convoluted, hard to follow mess." If you
> know that:
>
> <name> = lambda *args, **kwds: <expr>
>
> is eqivalent to:
>
> def <name>(*args, **kwds):
> return <expr>
>
> then it's quite straightforward to translate from one to the other.
I think that Charlie's point is that, when you use "def <name>", you have
<name> polluting your namespace. The whole program becomes harder to
understand because you can't ignore <name> anywhere, even if it was only
ever intended to be used in one place. It's a good point, and reasonable
people can disagree about whether the namespace pollution or the
unreadability of lambda is a bigger problem.
I've used lambda from time to time, but only socially, and I can quit any
time I want...
-- Walt
More information about the Python-list
mailing list