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

Antoon Pardon apardon at forel.vub.ac.be
Tue Oct 12 04:15:21 EDT 2004


Op 2004-10-11, Jeff Shannon schreef <jeff at ccvcorp.com>:
> Clark C. Evans wrote:
>
>>On Mon, Oct 11, 2004 at 10:54:05AM -0700, Jeff Shannon wrote:
>>| 
>>| .... It 
>>| seems to me that the benefits of having lambda are outweighed by the 
>>| fair amount of extra mental space that they use up.  It just strikes me 
>>| as too much of a special case to deserve special syntax that has 
>>| absolutely no parallel elsewhere in Python.
>>
>>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, with the 
> assumption that much of the code that one reads will be code written by 
> someone else.  I do care how readable your code is, because (at least in 
> principle) someday I may need to maintain it.  ("If you don't like X, 
> don't use it, but let others use it if they like" seems to be much more 
> Perlish than Pythonic, at least IMHO.)
>
> Lambdas are hard to read, because they're significantly different, 
> syntactically, from any other construct in the language

I didn't find them so. On the other hand I find having to come up
with a name for a function can be very inconvenient and not worth
the trouble. If python wants functions to be full fledged objects,
is needs some way to have unnamed functions, just as you can have
unnamed lists, numbers, instances etc.

Can you imaging the protest, from people if it would be decide
that no unnamed entities van be used. If you want to use a number
or a list, as an argument you first have to name it and then use
the name as argument. Well the reason for having anonymous numbers
and lists is the same reason for having anonymous functions.


> -- it's not that 
> I'm _unwilling_ to learn, it's that it is actively *difficult* to learn 
> because it doesn't fit well, conceptually, into the rest of the 
> language, so there's a mental impedance barrier that must be overcome.  
> In order to explain lambdas to someone who is not already familiar with 
> them, you have to explain first that it's kind of like a function def, 
> except that it uses totally different syntax (aren't function defs 
> supposed to use parens?)

The problem is IMO that python uses two different kinds of ways to
assign an object to a name. You have the assignment and you have the
class and def statements. I would consider de class and def statements
the odd man out, because they combine the construcion of the object
with naming it, where normally the two are seperated.

-- 
Antoon Pardon



More information about the Python-list mailing list