Draft Pep (was: Re: Let's Talk About Lambda Functions!)

François Pinard pinard at iro.umontreal.ca
Mon Aug 5 14:19:21 CEST 2002

[Tim Peters]

> People slinging GUI callbacks for a living could surely contribute more
> compelling examples [of needing lambda].

I did such exercises too, and saw that `lambda' yields a slightly more
compact reading.  I tried with and without `lambda', and both are OK.
In-lining a few `def' for defining a callback does not disrupt legibility.
Especially given that they only work in simpler and less frequent cases,
as for non-trivial things, callbacks are better presented as bound methods.

The only slightly annoying thing when _not_ using `lambda' is having to
choose a name for the function to be called.  These things do not occur that
often in practice, and moreover, almost always in the same simple contexts
from GUI to GUI: naming habits stick quickly, and the annoyance disappears.

Moreover, some GUI builders (I'm thinking about `libglade') suggest callback
names which are regular and logical, and which also quickly become habits.
So, even within GUI callback contexts, my experience tells me that we can
very easily and comfortably live without `lambda'.

François Pinard   http://www.iro.umontreal.ca/~pinard

More information about the Python-list mailing list