Securing a future for anonymous functions in Python

Jacek Generowicz jacek.generowicz at
Mon Jan 10 09:59:18 CET 2005

"Anna" <annaraven at> writes:

> With class and def, I at least have a *name* to start with - class
> Square pretty obviously is going to have something to do with
> geometric shapes, I would hope (or maybe with boring people...).

Or maybe with multiplying something by itself. Or maybe the author
made some changes in his program, and forgot to rename the class
sensibly, and the class' functionality has nothing to do with squares
of any sort any more. Or maybe he felt the name "Square" was very
appropriate for something else in his program and inadvertently gave
the same name to two different entities thereby clobbering the one
whose use was intended at this point.

> def getfoo() tells me I'm the function is likely to go elsewhere and
> get something. It's a *start*,

All too often a start in the wrong direction.

> a handle, to deciphering whatever the following statements are
> doing. (Yes, I realize that often class and function names suck

Yup. I waste quite some time because of crappily chosen names.

> - but more often than not, they give *some* clue).
> Whereas, with lambda - I have *nothing* to go on.

Aaah. OK, you object to lambda because it gives you no clue as to what
the function does, rather than with the word "lambda" itself? Is that

So, IIUC, you consider

   def add_one(x):
       return x+1
   map(add_one, seq)

to be clearer than

   map(lambda x:x+1, seq)


> With lambdas, all I know is that the programmer wanted to hide
> whatever it is the program is doing behind the curtain...

I find this a strange way of looking at it, given that, with lambda,
what the program is doing is right there in front of your very eyes at
the very point at which it is doing it. Were there a name, _then_ you
could argue that the functionality is hidden ... and you would have to
look the name up, to make sure that it really represents what you
inferred it meant (and, to be absolutely sure, you'd have to double
check that it hasn't been rebound by some other part of the program in
some nasty way). None of these problems arise with lambda.

> IMHO, YMMV, etc etc

Of course. Same here.

> Personally, I like lambdas less than regular expressions (of which
> I'm particularly UNfond but understand their usefulness at
> times). At least with regular expressions - I know that the
> gibberish I need to decipher (probably) has to do with text
> parsing...

Hmm, that tells you about as much as lambda does. With lambda you know
that the gibberish you need to decipher has to do with functions :-)

More information about the Python-list mailing list