I sing the praises of lambda, my friend and savior!
Jeff Shannon
jeff at ccvcorp.com
Mon Oct 11 14:58:44 EDT 2004
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 -- 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?), and you don't explicitly return anything even
though it *does* return a value, and oh yes, you can't actually use
statements because it has to be a single expression (and then you get to
explain the difference between statements and expressions, and explain
*why* there's a difference and that it really is a good thing)...
That's a lot of special treatment for those cases where there actually
might be a slight advantage to using an anonymous function, and "Special
cases aren't special enough to break the rules." Lambdas *do* break
many of Python's usual rules.
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list