Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'argument': 0.05; 'insert': 0.05; 'globally.': 0.07; 'suddenly': 0.07; 'assuming': 0.09; 'caller': 0.09; 'cc:addr:python-list': 0.11; 'thread': 0.14; '-tkc': 0.16; '09:00,': 0.16; 'caused.': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'globals': 0.16; 'mutated': 0.16; 'sys.modules': 0.16; 'wrote:': 0.18; 'module': 0.19; 'pieces': 0.19; '(the': 0.22; '>>>': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'creating': 0.23; 'finally,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'change,': 0.30; "i'm": 0.30; 'argue': 0.31; 'constant': 0.31; 'globally': 0.31; 'idea,': 0.31; 'this.': 0.32; 'stuff': 0.32; "we're": 0.32; 'minimal': 0.33; 'johnson': 0.35; 'but': 0.35; 'charset:us-ascii': 0.36; 'should': 0.36; 'fact': 0.38; 'does': 0.39; 'bad': 0.39; 'weight': 0.39; 'sure': 0.39; 'full': 0.61; 'to:addr:gmail.com': 0.65; 'idiot': 0.84; 'protocol,': 0.84; 'received:50.22': 0.84; 'side-effects': 0.84; 'subject:Global': 0.91; 'trouble.': 0.91; 'rick': 0.93 Date: Tue, 12 Nov 2013 11:45:09 -0600 From: Tim Chase To: Rick Johnson Subject: Re: PyMyth: Global variables are evil... WRONG! In-Reply-To: <2a325d8a-a242-4f2a-861b-9b786600f886@googlegroups.com> References: <7b97786a-2aaf-454c-8c3a-1c19d20d4345@googlegroups.com> <4bef88d0-d3eb-42e5-ac8e-288c629c528e@googlegroups.com> <2a325d8a-a242-4f2a-861b-9b786600f886@googlegroups.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com Cc: python-list@python.org 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1384278220 news.xs4all.nl 15956 [2001:888:2000:d::a6]:32841 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59225 On 2013-11-12 09:00, Rick Johnson wrote: > Because the constant PI should never change. Sure we can > argue about granularity of PI, but that argument has no > weight on the fact that PI should be a constant. > > By placing PI in the module "math", we are creating a pseudo > interface. We (the creators) are "assuming" that PI will be a > constant and never change, and the caller is assuming that > pi will remain static, but not only can it be mutated, it > can be mutated globally. But the module-scoping of "globals" is perfectly valid: >>> print(math.PI) 3.1415926535897932 >>> print(Magnum.PI) "Tom Selleck" As an example from the stdlib of setting globals via a protocol, locale.setlocale() does exactly this. So I'm not sure why you have your knickers in a knot. Module-level items can be accessed globally (though often a bad idea, or at least you have to beware of side-effects where other things might break), and if you don't like the "modules are not objects", someone in this thread already showed you that you can insert objects/classes into the sys.modules and get full getter/setter functionality with minimal trouble. Finally, we're all (mostly) consenting adults here. If I want to be an idiot and math.PI = 3.14 and suddenly stuff breaks, I get to keep all the pieces my breakage caused. -tkc