Path: csiph.com!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subject:Python': 0.05; 'attributes': 0.07; 'cc:addr:python-list': 0.09; 'example:': 0.10; 'def': 0.13; 'thu,': 0.15; '"global"': 0.16; 'cease': 0.16; 'code?': 0.16; 'contrived': 0.16; 'frees': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'magic': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'all,': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'logical': 0.22; 'sep': 0.22; 'suppose': 0.22; 'tried': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'developers': 0.26; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'this.': 0.28; 'other,': 0.29; 'pep': 0.29; 'work.': 0.30; 'code': 0.30; 'posts': 0.30; 'especially': 0.32; 'statement': 0.32; 'getting': 0.33; 'hopefully': 0.33; 'instances': 0.33; 'worked': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'according': 0.36; 'but': 0.36; 'there': 0.36; '(and': 0.36; 'assigned': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'why': 0.39; 'where': 0.40; 'some': 0.40; 'your': 0.60; 'hope': 0.61; 'more': 0.63; 'sample': 0.63; 'chrisa': 0.84; 'forced': 0.84; 'to:none': 0.91; 'proposal,': 0.95 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=qDVznjGiz97WjYgN/MI7ZjGhSD0+HJnHO7VQcUMNauA=; b=ca+BX0QnbRgHYgonXttZp6P8Q/9KylxQQATE0PbItnch9PLt+2WIWA3q8Fs3VLLT5J MrcDFtUFtyLnTt1QKl2p8LE8p4L2bHkOaGJsfH5gyOwq/K+KkJDCumKpLFnZ/lPZD2sI TS6bdG8pjy8ynFUbO3SLuHbzV4ZNvC+cyvbHW5vGbEIPDjJrRRiPPr/mWTxg+ynTxWpd YLWylioQ2VrrATPjVLWXK66AGQW3CdEmWdWlUM8QoSLeJp0/Bg72LYCjSVkDh6rE8OLN UrIOY+DkhqY/CblCUR4FO3fp3Un2Y8weOiQx484o/U6fXmSN7C17HYDiUW4zF8p1uZkB HUgQ== MIME-Version: 1.0 X-Received: by 10.107.36.8 with SMTP id k8mr23575886iok.157.1441289029782; Thu, 03 Sep 2015 07:03:49 -0700 (PDT) In-Reply-To: <3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com> References: <3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com> Date: Fri, 4 Sep 2015 00:03:49 +1000 Subject: Re: Python handles globals badly. 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.20+ 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: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1441289040 news.xs4all.nl 23776 [2001:888:2000:d::a6]:35764 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95935 On Thu, Sep 3, 2015 at 11:22 PM, wrote: > Sample "Good": > module A > _x = 0 > > def y(): > _x=1 > > > why - this I have tried and try to explain in my and your posts > in the hope a PEP will arise which frees me and hopefully > a lot other developers getting forced to use "global" > (If developers need this "global" - ok, but I and > hopefully more want not to be forced with that > code-contaminator, especially having a lot more vars) Okay. Let's suppose that some magic is worked out that makes this work. Now let's try this example: def x(q): for word in generate_words(): if word.matches(q): return word def y(): word = x("blue") otherword = x("green") if word < otherword: return otherword return x("red") How would you reason about this code? Would you not expect that the instances of 'word' in each function are completely independent? (And while this is a contrived example, the exact same thing happens *a lot*, where the name used in a "return" statement is the same as the name that thing gets assigned to. After all, if it's a logical name for that thing in one place, it's likely a logical name in the other, too.) According to your proposal, they would cease to be independent if the module grows an attribute 'word'. Since, in Python, such attributes can be injected from outside, there is literally no way to reason about this code in isolation. That makes it very difficult to track down problems. Definitely do not like this. ChrisA