what is lambda used for in real code?
Adam DePrince
adam at cognitcorp.com
Tue Jan 4 22:38:12 EST 2005
On Fri, 2004-12-31 at 17:36, Steven Bethard wrote:
> Adam DePrince wrote:
> > Lets not forget the "real reason" for lambda ... the elegance of
> > orthogonality. Why treat functions differently than any other object?
> >
> > We can operate on every other class without having to involve the
> > namespace, why should functions be any different?
>
> Yup. I think in most of the examples that I didn't know how to rewrite,
> this was basically the issue. On the other hand, I do think that
> lambdas get overused, as indicated by the number of examples I *was*
> able to rewrite.[1]
>
> Still, I have to admit that in some cases (especially those involving
> reduce), I wish the coder had named the function -- it would have given
> me a little bit more documentation as to what the code was trying to do.
This is a long standing philosophical issue that really shouldn't impose
itself on the language. Do you document, and risk that the
documentation doesn't match the code, or do you use the code itself as
documentation.
Leaving, or even expanding upon, anonymous functions permits the
programmer to choose their stance in the above debate; you can still
write
# If I had to give this function a name, it would be ...
before or after the lambda to elect the former option. The removal of
anonymous functions, however, forces the former option. Even if option
latter is misguided, one of the guiding principles of Python is that we
are all consenting adults free to do dumb things.
- Adam
Adam DePrince
More information about the Python-list
mailing list