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

Clark C. Evans cce at clarkevans.com
Mon Oct 11 15:16:38 EDT 2004


On Mon, Oct 11, 2004 at 11:58:44AM -0700, Jeff Shannon wrote:
| >If you don't like lambda -- don't use it.   Just beacuse you are
| >unfamilar with a very helpful construct and are unwilling to learn
| >does not mean you should prevent others from continuing to enjoy 
| >one of the more pleasant aspects of Python.
| 
| Except that one of the design principles of Python is that it being easy 
| to *read* is more important than being easy to write

Exactly!  Lambdas make my code easy to read and therefore more
understandable.   I don't use them beacuse they are easier to write,
I use them beacuse they make reviewing source code easier:

  - they put simple expressions that are arguments right
    where they are used
    
  - they don't create random names that you have to worry 
    about name collision or finding something meaningful
    (and not distracting)
    
  - you are certain to know that the chunk of code is not
    used anywhere else, that is, you can freely modify it

Lambdas are all about making code more maintainable.

| Lambdas are hard to read, 

This is _your_ opinion; lots of other people disagree.

| because they're significantly different, 
| syntactically, from any other construct in the language 

This argument is just bogus.  There are lots of things in Python
that are significantly different from each other:

  - functions that return functoins, and hence can().be().chained()
  - using expressions as function arguments
  - list comprehensions
  - *args and **kwargs
  - overridable operators
  - classes, meta-classes
  - etc.

In any of these cases one _could_ of course, find a similar way
to do it with just a turning machine.  But this isn't the point,
the point is to give special syntax to common things that have
specific meaning so that they are easily recognized.

Best,

Clark




More information about the Python-list mailing list