I sing the praises of lambda, my friend and savior!
Jeff Shannon
jeff at ccvcorp.com
Mon Oct 11 13:54:05 EDT 2004
Clark C. Evans wrote:
>No joke. For the common case above, which occurs _everywhere_
>in my 'deferred execution' code, one would write:
>
> def somerandomname(args):
> body
> func(arg, somerandomname)
>
>So, you've taken something that is a perfectly clear one-liner and
>converted it into a 3 line chunk of code with _zero_ added clarity,
>in fact, I'd say you've dramatically reduced clarity by requiring
>the a name be 'minted'. Ugly.
>
I don't agree. I *still* have to stop and think every time I see a
lamba -- they parse completely differently in my mind than anything else
in Python does, and they confuse me every time. Yes, defining a small
function requires two extra lines... but, y'know, it's not like my
editor is going to run out of paper. And I find that a well-chosen
name, even for a single-use thing like this, greatly adds clarity. To
my mind, calling this func_callback(), or some such descriptive name,
makes the intent *much* more clear than 'lambda' does.
>Multiply this by 10x in one of my
>source files and you've taken something perfectly readable and
>turned it into maze of confusion. This _hides_ the true intent
>rather than making it clear that the function is temporary thingy.
>
>
Only when one is already familiar with lambdas. I've gotten to the
point where I *can* understand them, but it's still a struggle. It
seems to me that the benefits of having lambda are outweighed by the
fair amount of extra mental space that they use up. It just strikes me
as too much of a special case to deserve special syntax that has
absolutely no parallel elsewhere in Python.
>| Well, if lambda is removed (or not ;-), I hope an anonymous def
>| expression is allowed, so we can write
>|
>| obj.f = def(args):
>| body
>| or
>|
>| obj.f = def(args): body
>|
>| or
>|
>| obj.f = (
>| def(args):
>| body
>| )
>
>Ewww. How is this better than lambda? Let's keep lambda, no?
>
>
I certainly agree that none of these examples strike me as less
troublesome than lambda. Indeed, the second one effectively *is* lambda
syntax, except with added parens and a name change. And the others both
scream out that there *will* be problems with indenting properly.
I remain unconvinced that the utility of anonymity is so great that
either special case is justified.
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list