Replacing lambda() examples... (Re: Lambda going out of fashion)

Petr Prikryl Prikryl at skil.cz
Thu Dec 23 09:34:46 CET 2004


Hi,

I suggest to post here simplified examples that
use the lambda to be replaced by non-lambda 
Pythonic solutions. The ideal result would be 
the set of rules, how lambdas can be replaced
by in future when they become deprecated.

Less ideal but valuable may be short examples
and counter-examples of using or not using
the lambdas.

While following the thread "Lambda going out of fashion"
I have read cries for not throwing lambdas away and also
the opposite opinions. I believe that the theme requires
more examples to convince. I personally incline towards
the experience of Craig Ringer (see other notices below):

"Craig Ringer" wrote in message news:<mailman.8311.1103787850.5135.python-list at python.org>...
> [...]
> I also make signficant use of Lambda functions, but less than I used to.
> I've recently realised that they don't fit too well with Python's
> indentation-is-significant syntax, and that in many cases my code is
> much more readable through the use of a local def rather than a lambda.
> 
> In other words, I increasingly find that I prefer:
> 
> def myfunction(x):
>     return x**4
> def mysecondfuntion(x):
>     return (x * 4 + x**2) / x
> make_some_call(myfunction, mysecondfunction)
> 
> to:
> 
> make_some_call( lambda x: x**4, lambda x: (x * 4 + x**2) / x)
> 
> finding the former more readable. The function names are after all just
> temporary local bindings of the function object to the name - no big
> deal. Both the temporary function and the lambda can be used as
> closures, have no impact outside the local function's scope, etc. I'd be
> interested to know if there's anything more to it than this (with the
> side note that just don't care if my temporary functions are anonymous
> or not).
> [...]

I believe that GvR has a lot of experience and he proved
to be very pragmatic. If he thinks that lambdas bring more
problems than they solve, it may be some truth in it.

I also believe that lamda-trained programmers think 
a bit differently which does not automatically mean
that they think the best way in all cases.

Waiting for interesting discussion,
  Petr

-- 
Petr Prikryl (prikrylp at skil dot cz) 

---
Odchozí zpráva neobsahuje viry.
Zkontrolováno antivirovým systémem AVG (http://www.grisoft.cz).
Verze: 6.0.821 / Virová báze: 559 - datum vydání: 21.12. 2004
 



More information about the Python-list mailing list