I sing the praises of lambda, my friend and savior!

Clark C. Evans cce at clarkevans.com
Mon Oct 11 12:36:21 EDT 2004


What? is lambda is going away?  Say it ain't so!

On Fri, Sep 17, 2004 at 08:26:19AM +0000, Bengt Richter wrote:
| >f = lambda args: body
| >   is equivalent to
| >def f(args): body

Not really -- the item above is _bad style_, people write,

  def f(args):
      body

|    obj.f = lambda args: body

Or more commonly,

  func(arg, lambda args: body)

| I'd rather use lambda.

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.  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.

| >Not that it's coming any time soon, but Python 3000 is supposed to remove 
| >lambda functions

Expect me to whine very loudly on a daily basis when Python 3000 
becomes near.  In fact, let the preemptive supplication begin.

| 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?

Clark

-- 
Clark C. Evans                      Prometheus Research, LLC.
                                    http://www.prometheusresearch.com/
    o                               office: +1.203.777.2550 
  ~/ ,                              mobile: +1.203.444.0557 
 //
((   Prometheus Research: Transforming Data Into Knowledge
 \\  ,
   \/    - Research Exchange Database
   /\    - Survey & Assessment Technologies
   ` \   - Software Tools for Researchers
    ~ *



More information about the Python-list mailing list