Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Kevin Conway Newsgroups: comp.lang.python Subject: Re: Namespaces are one honking great idea Date: Sun, 03 Jul 2016 22:02:27 +0000 Lines: 94 Message-ID: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com> <57788a2f$0$22141$c3e8da3$5496439d@news.astraweb.com> <57789F3D.7000809@stoneleaf.us> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de GYpZMIq44z5lPKpYG2t1vgi1nuRkeLEj1wyP/iVspK8w== 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; 'broken': 0.03; 'static': 0.03; 'classes,': 0.05; 'cpython': 0.05; 'paths': 0.05; 'objects,': 0.07; 'tool,': 0.07; '(without': 0.09; 'derived': 0.09; 'likewise': 0.09; 'namespace': 0.09; 'satisfy': 0.09; 'wrong,': 0.09; 'python': 0.10; 'def': 0.13; 'suggest': 0.15; 'argument': 0.15; 'commit': 0.15; "hasn't": 0.15; 'variables': 0.15; 'already,': 0.16; 'classes)': 0.16; 'dotted': 0.16; 'lexical': 0.16; 'namespace,': 0.16; 'namespace.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Namespaces': 0.16; 'wanted.': 0.16; 'wrote:': 0.16; 'nested': 0.18; 'refers': 0.18; "shouldn't": 0.18; '>': 0.18; 'creates': 0.18; 'language': 0.19; '>>>': 0.20; 'meant': 0.22; 'saying': 0.22; 'names.': 0.22; 'oriented': 0.22; 'suppose': 0.22; 'programming': 0.22; 'code.': 0.23; 'bit': 0.23; 'implemented': 0.24; 'header:In-Reply-To:1': 0.24; 'discussion': 0.24; 'module': 0.25; 'example': 0.26; 'linux': 0.26; 'rest': 0.26; 'skip:" 20': 0.26; 'earlier': 0.27; 'community.': 0.27; 'mostly': 0.27; 'not.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'leveraging': 0.27; 'idea': 0.28; "skip:' 10": 0.28; 'went': 0.28; 'behaviour': 0.29; 'oop': 0.29; '~ethan~': 0.29; 'objects': 0.29; "i'm": 0.30; 'classes': 0.30; 'url:mailman': 0.30; 'code': 0.30; 'skip:& 30': 0.30; 'rules': 0.31; 'up.': 0.32; 'realize': 0.32; 'statement': 0.32; 'getting': 0.33; 'class': 0.33; 'problem': 0.33; 'url:python': 0.33; "d'aprano": 0.33; 'decorators': 0.33; 'steven': 0.33; 'suddenly': 0.33; 'similar': 0.33; 'url:listinfo': 0.34; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'instance': 0.35; 'quite': 0.35; 'express': 0.35; "isn't": 0.35; 'but': 0.36; 'url:org': 0.36; '(and': 0.36; '(3)': 0.36; 'cases': 0.36; 'modules': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'method': 0.37; 'say': 0.37; '(2)': 0.37; 'detail': 0.38; '(1)': 0.38; 'self': 0.38; 'anything': 0.38; 'mean': 0.38; 'why': 0.39; 'sure': 0.39; 'whatever': 0.39; 'does': 0.39; "didn't": 0.39; 'enough': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'easy': 0.60; 'your': 0.60; 'real': 0.62; 'more': 0.63; 'qualified': 0.63; 'within': 0.64; 'world': 0.64; 'believe': 0.66; 'skip:\xc2 10': 0.67; '(5)': 0.72; 'jul': 0.72; 'special': 0.73; 'satisfied': 0.83; '(ref:': 0.84; 'change?': 0.84; 'concept.': 0.84; 'construct': 0.84; 'decorators.': 0.84; 'to:name:python': 0.84; 'belief': 0.91; 'ethan': 0.91; 'furman': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=0WbdxLxM4P9POykuqT3O2+2e7PLGXvHlAbSfN0BnACY=; b=if5nrUOe39dKn854Y7MJR+UzeNs7wdxuA38baGiUY296qFMLMRsBhz7gmyMNdRI9Gd uQvUbzOR4NbnUR8LrIf3rErgJEx6heZZdS6bH7VQsZZKULS29DVorpnQ33RkeiYjHj+A k3uYb6vXu7yN0O7r0d+t8GKGcc0ir1rV/4AaCt8/G9NlPRTJMbm9m5648aBwNH2TqetH iNZJKtjN3emEdP3HhIo+8pYelNoZW88gXK5OVhKwEcrNEMBvaVQ/sg8cLm7TbZ8FQHg8 PLQaoHZ2hBuaBpKRanrh3Vwr7xZWoYU00Z9cfjr7HzBrlGA7uZxiuT5VqmeymCJZN8ZC FChA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=0WbdxLxM4P9POykuqT3O2+2e7PLGXvHlAbSfN0BnACY=; b=Xx+0nhfKkAwBTdbSdMdAHoShAaTJovcL5B26RNqipReZAmYY6gVJUbi8u6itMDrBYc jDIwR4IxCmUc1DLpT6zZacoB5cHq9bGWo2obdf7i+PxAbZ45fVe6SxPzezQ9jak7aUAF VQMKM3YpZ42NqTO5l7L+VVH/wRJkau+HuP12QkVoVc8kWIdBV/qZT7APOOF9Dth4AnCz f31uBu5Yb4/fl29nNy+CFWI9PcQQ1k+qKloNWlqHIKrBjaBpaMbAAwMgT3QZwvl/W/ZB B8Pp+Qp2f4E6Gx9iofzWPA2WbagwBo8ri+2E9wddGnEZQxu0JW9NTXumuBQ0GyIVtVUp YuPg== X-Gm-Message-State: ALyK8tK5aBsIFnGSHd4oIA8FaTCoMyh7KfOVw0dT18l5cFnKTw8boJUa0NcBcKzgyjajPmIsc0bhkI6ZVmSCYw== X-Received: by 10.176.5.3 with SMTP id 3mr3883898uax.52.1467583356716; Sun, 03 Jul 2016 15:02:36 -0700 (PDT) In-Reply-To: <57789F3D.7000809@stoneleaf.us> X-Content-Filtered-By: Mailman/MimeDel 2.1.22 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: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com> <57788a2f$0$22141$c3e8da3$5496439d@news.astraweb.com> <57789F3D.7000809@stoneleaf.us> Xref: csiph.com comp.lang.python:111015 >> Regardless, all use cases you've listed are already satisfied by use of >> the static and class method decorators. Methods decorated with these do >> not require an instance initialization to use. > And are significantly less easy to use, as the functions MUST refer to each > other by their dotted names. My response to this may come off as a bit glib, but it isn't intended that way. If the problem with using classes to satisfy the namespace need is that it's unwieldy to use dot qualified paths then isn't that quite similar to saying namespaces are unwieldy? Leveraging classes as a nested module creates a de-facto internal namespace of "cls" for self reference and I'm unsure of why that is unwanted but "module.namespace.blah" is wanted. I suppose my issue is not so much that namespace objects are a bad idea as that the proposal does little to express why the existing tools are deficient enough to require a new concept. > For the proponents of namespace, what is deficient in the above example > that necessitates a language change? >> It's not a language change. Perhaps. My argument is that anything that introduces a new class-like construct and set of lexical scoping rules is a language change. For example, if this change went into 2.7.13 would Jython suddenly be broken because it hasn't implemented the new scoping rules? >> IIRC, classes came about as a "module in a module". > I'm pretty sure they did not. Object oriented programming (and hence > classes) came about from simulating real world objects, hence the > name: I realize my statement was ambiguous. I didn't mean to suggest that classes, as an idea and OOP tool, were derived from the concept of a namespace. I meant to say that the Python implementation of classes is quite similar to the implementation of modules in the cPython code. The commit messages from the earlier days (ref: ab5db02) don't carry much detail so I'm mostly basing my belief of the implementation similarities and anecdotes from the community. Right or wrong, I don't believe it has much weight in the namespace discussion and I shouldn't have brought it up. On Sun, Jul 3, 2016, 00:17 Ethan Furman wrote: > On 07/02/2016 08:44 PM, Steven D'Aprano wrote: > > > Try getting this behaviour from within a class: > > > > > > class Food(metaclass=Namespace): > > > > # (1) no special decorators required > > def spam(n): > > return ' '.join(['spam']*n) > > > > # (2) can call functions from inside the namespace > > breakfast = spam(5) > > > > # (3) no "cls" or "self" argument > > def lunch(): > > # (4) can access variables using their undotted name > > return breakfast + ' and eggs' > > > > def supper(): > > # (5) likewise functions (a special case of #4) > > return lunch() + ' and a fried slice of spam' > > > > def mutate(n): > > # global inside the namespace refers to the namespace, > > # not the surrounding module > > global breakfast > > breakfast = spam(5) > > > Can you do all of that with an ordinary class? > > You can get #2 already, but not the rest (without your spiffy code ;) : > > Python 3.5.1+ (3.5:f840608f79da, Apr 14 2016, 12:29:06) > [GCC 4.8.2] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> class Huh: > ... def blah(text): > ... print('blah blah %s blah blah blah' % text) > ... blah('whatever') > ... > blah blah whatever blah blah blah > > -- > ~Ethan~ > -- > https://mail.python.org/mailman/listinfo/python-list >