Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!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.026 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'parameters': 0.04; 'explicitly': 0.05; 'class,': 0.07; 'explicit': 0.07; 'agree,': 0.09; 'python': 0.11; 'bind': 0.16; 'declaration': 0.16; 'definition.': 0.16; 'local.': 0.16; 'reedy': 0.16; 'unbound': 0.16; 'sat,': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'code,': 0.22; 'errors.': 0.24; 'switched': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'related': 0.29; 'needed.': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'another': 0.32; 'beginning': 0.33; 'not.': 0.33; 'received:google.com': 0.35; 'there': 0.35; 'consistent': 0.36; 'yield': 0.36; 'subject:?': 0.36; 'should': 0.36; 'two': 0.37; 'others.': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'that,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'ian': 0.60; 'new': 0.61; 'entire': 0.61; 'simply': 0.61; 'first': 0.61; 'name': 0.63; 'such': 0.63; 'needing': 0.65; 'determine': 0.67; '10:32': 0.84; 'ever.': 0.84; 'hardly': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=cOmh78crTwnB8bxmRZqVGSOWXXMFQC29HMwYpsLL8Oc=; b=GSIKgvIutfVLngaFGXRRBeMox0oCdTximOg+3r/dFd5hb4pEKRlwDUlKBfA2lnjwsX J/Rc7hGu9KVTO7Qhuk6/XUeZ/fkoP/HiE1yZc7gpthFS+FtdpXKdkOAcWBZ8i6MjkVNN oNIGTdAbT4RZ7mr0T0JoMykE4ypRPvfrcgpYulyavP98kY4QZebmiDoJF6OtchuXMihF m5/E8hUCvWEidHyg5FtB+9vu5ASBnFzAnZ3YMm1hZfLtJsns3DxDVK71wxmkMKxYyU/H vTm8uDzcLK8j+9c4BZ7h1IitFXD0XPNoYIAG1VJPWVhc2222sLkcqefKIOD1TiF2gFLM YRGQ== X-Received: by 10.68.28.232 with SMTP id e8mr18502086pbh.94.1372571212987; Sat, 29 Jun 2013 22:46:52 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <2a2072e3-4b12-4ada-872c-1240d2379928@googlegroups.com> <51cf2b49$0$29999$c3e8da3$5496439d@news.astraweb.com> <2f5e7801-a4cd-4d01-a1e7-7f67bca18199@googlegroups.com> <51cf3695$0$29999$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Sat, 29 Jun 2013 23:46:12 -0600 Subject: Re: Closures in leu of pointers? To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372571221 news.xs4all.nl 15881 [2001:888:2000:d::a6]:52823 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49474 On Sat, Jun 29, 2013 at 10:32 PM, Terry Reedy wrote: > On 6/29/2013 5:21 PM, Ian Kelly wrote: >> Or simply an explicit declaration of scope at the beginning of the >> function definition. > > One of the reasons I switched to Python was to not have to do that, or > hardly ever. For valid code, an new declaration is hardly needed. Parameters > are locals. If the first use of another name binds it (and that includes > import, class, and def), it is local. If the first use of does not bind it, > it had better not be local (because if it is, there well be an exception). > If there are branches, each should be consistent with the others. One should > only need two readings to understand and fix unbound local errors. In general I agree, although when reading code I would definitely prefer if the locals were declared. On a related note, I think that generator functions should in some way be explicitly marked as such in the declaration, rather than needing to scan the entire function body for a yield statement to determine whether it's a generator or not.