What does Python fix?
Tim Peters
tim.one at home.com
Fri Jan 25 02:01:59 EST 2002
[Jason Orendorff, shows vanilla use of nested scopes]
[David Eppstein]
> Ok, you've convinced me that expanding lambda into unnamed code-blocks is
> unnecessary, and confirmed Tim's point that naming the code blocks can be
> better than lambdas for readability.
I was just pulling James Althoff's leg -- he expected it, and I enjoy it.
Still, this is just another variant of "the eff-bot's favourite lambda
refactoring rule" (from a post by Fredrik Lundh):
1) write a lambda function
2) write a comment explaining what the heck that lambda does
3) study the comment for a while, and think of a name that captures
the essence of the comment
4) convert the lambda to a def statement, using that name
5) remove the comment
lambdas didn't really add anything to Python, except to give ex-Schemers
false hope <wink>.
> Although in that particular example, I'm not convinced that
> having any kind of nested function is better than just expanding the
> expressions they represent in-line, with appropriate comments...
And once you've got that comment worked out, you can jump straight to the
effbot's step #3!
More information about the Python-list
mailing list