A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-May/079111.html below:

[Python-Dev] PEP 8: Discourage named lambdas?

[Python-Dev] PEP 8: Discourage named lambdas?Steven D'Aprano steve at pearwood.info
Sun May 4 11:39:48 CEST 2008
On Sun, 4 May 2008 01:24:54 am Alex Martelli wrote:
> On Fri, May 2, 2008 at 11:32 PM, Mike Klaas <mike.klaas at gmail.com>
> wrote: ...
>
> >  Sorry, that was a bad example.  It is obviously silly if the
> > return value of the function is callable.
>
> ...and yet it's *exactly* what keeps happening to lambda-happy
> programmers -- in production code as well as examples, and in
> major/famous projects too.  E.g., a simple google code search shows
> many Zope versions containing "Bucket=lambda:{}" instead of the
> obvious "Bucket=dict", 

In fairness, up until a few years ago, Bucket=dict wouldn't have worked. 
I'm sure there's a lot of Python programmers who learnt the language 
with version < 2.0 who still have blind-spots when it comes to types. I 
know I do (but I'm getting better with practice).

Besides, would that be any better written as this?

def Bucket(): return {}

I think not. This is not a "named lambda" problem, this is a "developer 
doesn't know how to use types" problem.


While we're discussing named lambdas, and at the risk of dragging this 
thread out even longer, here's one example where I would use one:

def parrot(args, transformation=None):
    if transformation is None: # Use an identity function.
        transformation = lambda x: x  
    for arg in args:
        do_something_with(transformation(arg))


Does anybody have any constructive comments to make about this usage?



-- 
Steven D'Aprano
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4