Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions Date: Thu, 30 Jun 2016 09:25:20 +0200 Organization: None Lines: 52 Message-ID: References: <85mvm5vrbw.fsf@benfinney.id.au> <0690f476-95ad-4dec-87e5-42ecee07fdcd@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: news.uni-berlin.de tbUwPAngzic9fRkSRG63ZQ/c7ylwLZGgeCP5UPrT/2nQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; '"""': 0.05; '*args,': 0.07; 'raises': 0.07; 'assigning': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'def': 0.13; 'argument': 0.15; '2016': 0.16; 'ah,': 0.16; 'foo():': 0.16; 'lambda': 0.16; 'programmers,': 0.16; 'readable': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:parameters': 0.16; 'sugar': 0.16; 'syntactic': 0.16; 'tracebacks': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'explicit': 0.22; 'lawrence': 0.22; 'component': 0.23; 'somewhere': 0.24; 'module': 0.25; 'header :User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'wonder': 0.27; 'looks': 0.29; '**kwargs)': 0.29; 'improves': 0.29; 'it\xe2\x80\x99s': 0.29; 'allows': 0.30; 'foo': 0.33; 'instead': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'why': 0.39; 'easily': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'received:de': 0.40; 'share': 0.61; 'provide': 0.61; 'side': 0.62; 'more': 0.63; 'eyes': 0.70; 'decorator:': 0.84; 'expressive': 0.84; 'suspicion': 0.84; 'understood.': 0.84; 'widespread': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd9781.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <85mvm5vrbw.fsf@benfinney.id.au> <0690f476-95ad-4dec-87e5-42ecee07fdcd@googlegroups.com> Xref: csiph.com comp.lang.python:110825 Lawrence D’Oliveiro wrote: > On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: > >> I would like to see a more Pythonic, more explicit and expressive >> replacement with its component parts easily understood. > > I don’t know why this fear and suspicion of lambdas is so widespread among > Python users ... former Java/C# programmers, perhaps? If there is "fear" I don't share it. However, for foo = lambda : there is syntactic sugar in Python that allows you to write it as def foo(): return with the nice side effects that it improves the readability of tracebacks and allows you to provide a docstring. So yes, assigning a lambda to a name raises my "suspicion". If a lambda is provided as an argument or as part of an expression I wonder how it is tested, and if even if it is trivial like def reduce(items, func=lambda x, y: x + y): ... the alternative def reduce(items, func=add): ... looks more readable in my eyes even though somewhere -- under the rug or in the operator module -- you need def add(x, y): """ >>> add(3, 4) 7 """ return x + y >> decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda func: decorator(func, *args, **kwargs) > > Ah, I see why there are 3 lambdas, instead of 2. It’s so that you can write I have a suspicion that there would not have been a correction "I see why there are three functions instead of two" ;)