lambda (and reduce) are valuable

Chris Mellon arkanes at gmail.com
Sat Dec 10 08:06:37 EST 2005


On 12/9/05, David Isaac <aisaac0 at verizon.net> wrote:
> >>>     Jibes against the lambda-clingers lead eventually to serious
> >>>     questions of style in regard to variable namespacing,
> >>>     lifespan, cleanup, and so on:
> >>>
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/ad0e15cb6b8f2c32/
>
> Alan Isaac <aisaac0 at verizon.net> wrote:
> >> #evaluate polynomial (coefs) at x using Horner's rule
> >> def horner(coefs,x): return reduce(lambda a1,a2: a1*x+a2,coefs)
>
> "Cameron Laird" <python-url at phaseit.net> wrote in message
> news:dn7ibf$id0$1 at lairds.us...
> > I *think* you're supporting a claim
> > about the value of lambda with a specific example.  Do I have that
> > right?  Are you saying that your definition of horner() would suffer
> > greatly without lambda?
>
> It is a simple example of how lambda and reduce can be very expressive.
> Anyone who understands Horner's rule can see at a glance that this code
> implements it.  Anyone who has bothered to learn what lambda and reduce
> do can see at a glance what the algorithm is.
>
> It just cannot get simpler or more expressive.
>
> Suffer greatly?  Surely not.  For "suffer greatly" you would probably need
> to turn to people who do a lot of event-driven GUI programming.
> But suffer, yes.  Simplicity and expressiveness are valuable.
> That is the point.
>

As someone who does a tremendous amount of event-driven GUI
programming, I'd like to take a moment to speak out against people
using us as a testament to the virtues of lamda. Event handlers are
the most important part of event-driven code, and  making them real
functions with real names is crucial to maintainable code. The only
reason to ever use a lamdba in Python is because you don't want to
give a function a name, and that is just not a compelling use case for
GUI events.

> Cheers,
> Alan Isaac
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list