Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Jun 30 04:00:33 EDT 2016


On Thursday 30 June 2016 17:43, Lawrence D’Oliveiro wrote:

> On Thursday, June 30, 2016 at 7:26:01 PM UTC+12, Peter Otten wrote:
>> foo = lambda <args>: <expr>
>> 
>> there is syntactic sugar in Python that allows you to write it as
>> 
>> def foo(<args>):
>>     return <expr>
>> 
>> with the nice side effects that it improves the readability of tracebacks
>> and allows you to provide a docstring.
> 
> True, but then again the original had three lambdas, so one line would have
> to become at least 3×2 = 6 lines, more if you want docstrings.

I hear that we've passed "Peak Newlines" now, so adding extra lines will get 
more and more expensive. I guess languages like C and Java will soon have to be 
abandoned, and everyone will move to writing minified Javascript and Perl one-
liners.


>> def reduce(items, func=lambda x, y: x + y): ...
> 
> There was a reason why “reduce” was removed from being a builtin function in
> Python 2.x, to being banished to functools in Python 3.

Yes, and that reason is that Guido personally doesn't like reduce.



-- 
Steve



More information about the Python-list mailing list