[Python-ideas] a new lambda syntax
Oleg Broytman
phd at phd.pp.ru
Mon Oct 19 16:39:42 CEST 2009
On Mon, Oct 19, 2009 at 10:28:58PM +0800, starwing wrote:
> Oleg Broytman ??????:
>> Single-line lambdas are good enough,
>> and if you need more - just create a named function.
>>
> BUT, why we need a name? just to process something or make decide,
> sometimes code itself is enough.
A multiline function is certainly not a simple piece of code; it
requires documentation - docstring, comments - and the name is a part of
the documentation.
> and, is there performance problems when you define a inner function in
> another function? (that's, that function will define every time you call
> the function or not?)
A lambda, like an inner function, is recreated every time, so it's
certainly no better than a named function.
You should profile your program to prove there is really a performance
degradation. And if there is - create a global function instead.
Oleg.
--
Oleg Broytman http://phd.pp.ru/ phd at phd.pp.ru
Programmers don't die, they just GOSUB without RETURN.
More information about the Python-ideas
mailing list