Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'argument': 0.05; 'explicit': 0.07; 'assigning': 0.09; 'benefits,': 0.09; 'function,': 0.09; 'subject:module': 0.09; 'translate': 0.10; 'cc:addr:python-list': 0.11; 'times,': 0.14; 'declaration': 0.16; 'def.': 0.16; 'expression,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lambda': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'widget': 0.19; 'rules': 0.22; 'cc:addr:python.org': 0.22; 'skip:l 30': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'room': 0.29; "doesn't": 0.30; 'document.': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'implicit': 0.31; 'obscure': 0.31; 'really,': 0.31; 'skip:d 20': 0.34; 'basic': 0.35; 'agree': 0.35; 'objects': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'two': 0.37; 'list': 0.37; 'pm,': 0.38; 'ability': 0.39; 'either': 0.39; 'read': 0.60; 'expression': 0.60; 'simple': 0.61; "you're": 0.61; 'name': 0.63; 'more': 0.64; 'spot': 0.65; 'mar': 0.68; '26,': 0.68; 'obvious': 0.74; '2015': 0.84; 'decorate': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=AOojSKM4PdP2uh4sE0YWyoKAmF/Ec7fbfB04v1Mc/Bg=; b=m/5Aa2ZfyeARjCFtN019BNVVGrLQaSQ8sBZC8bHp8yVaL9ce8UkMIKjuGtjciZ1Abq 5JdmqMJQ+NlfVNQ+QuM5Z2Kf7z5aStZN6dmPkcP/xfZ2YtYDMr2A9+LYdIIb8FbSLKXV Y9HayrUhtU4Eh+0fIHvzzsRbephrPJY6s7mCTg7VQNALuyUHxzVhVKU/Ce8yN+YZuv/r J1vFwO7v+HIBLz84EzCjYrH06e5GcU3B9sml6pDNtleaHo0Vxnx9GWkejwn2j5YQQ5U5 lPdfHF9/0yn+K4Uct02BBslApMTpDBDbyjp3n1kxAMvaFIj1NCDauVFRjuuSTufMF8v4 5FXQ== MIME-Version: 1.0 X-Received: by 10.42.238.140 with SMTP id ks12mr37331238icb.12.1427365665217; Thu, 26 Mar 2015 03:27:45 -0700 (PDT) In-Reply-To: References: Date: Thu, 26 Mar 2015 21:27:45 +1100 Subject: Re: module attributes and docstrings From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427365668 news.xs4all.nl 2951 [2001:888:2000:d::a6]:36844 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:88040 On Thu, Mar 26, 2015 at 8:53 PM, Mario Figueiredo wrote: > However, lambda functions do read well in my mind and I find it hard > to spot where they obscure the code more than a function. So the > explicit vs. implicit part of the argument doesn't translate well with > me. I however agree that a function declaration brings other benefits, > like the ability to decorate or document. A function is a function is a function, so really, it's just a question of whether you create them with a statement (def) or an expression (lambda). Two basic rules of thumb: 1) If you're assigning a lambda function to a simple name, then you don't need it to be an expression, so use def. 2) If you're warping your function body to make it an expression, use def. Basically, look at the outside and look at the inside. In some cases, it's obvious that it's all expressions: # Sort a list of widget objects by name widgets.sort(key=lambda w: w.name) Other times, it's pretty obvious that you should be using statements: delete_name_if_blank = lambda w: delattr(w, "name") if w.name == "" else None list(map(delete_name_if_blank, widgets)) In between, there's a lot of room to call it either way. ChrisA