Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83279
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <andrew3@r3dsolutions.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'patterns': 0.04; 'class,': 0.07; 'modifying': 0.07; 'permitted': 0.07; 'practice,': 0.07; 'puts': 0.07; 'patterns,': 0.09; 'received:172.16.0': 0.09; 'rossum': 0.09; 'type,': 0.09; 'python': 0.11; 'mostly': 0.14; 'added.': 0.16; 'bool': 0.16; 'extensible': 0.16; 'instance;': 0.16; 'it."': 0.16; 'mean,': 0.16; 'merely': 0.16; 'objection': 0.16; 'portable,': 0.16; 'preserve': 0.16; 'singleton': 0.16; 'subclass': 0.16; 'subclasses': 0.16; 'subclassing': 0.16; 'well- known': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'library': 0.18; 'mechanism': 0.19; "python's": 0.19; 'later': 0.20; 'seems': 0.21; 'programming': 0.22; 'import': 0.22; '(in': 0.22; 'python?': 0.22; 'header:User-Agent:1': 0.23; 'typical': 0.24; "i've": 0.25; 'class.': 0.26; 'purposes': 0.26; 'header:In- Reply-To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'received:172.16': 0.29; 'character': 0.29; 'generally': 0.29; "doesn't": 0.30; 'contract,': 0.30; 'nature': 0.30; "i'm": 0.30; 'that.': 0.31; 'decimal': 0.31; 'types.': 0.31; 'workaround': 0.31; 'class': 0.32; 'community': 0.33; 'skip:d 20': 0.34; 'could': 0.34; 'created': 0.35; 'something': 0.35; 'definition': 0.35; 'objects': 0.35; 'point.': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'accessible': 0.36; 'curious': 0.36; 'installing': 0.36; 'method': 0.36; 'should': 0.36; 'wrong': 0.37; 'so,': 0.37; 'two': 0.37; 'clear': 0.37; 'to:addr:python-list': 0.38; 'issue': 0.38; 'contract': 0.38; 'pm,': 0.38; 'rather': 0.38; 'little': 0.38; 'does': 0.39; 'itself': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'users': 0.40; 'how': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'tell': 0.60; 'break': 0.61; 'extended': 0.61; 'mentioned': 0.61; 'new': 0.61; 'simple': 0.61; "you're": 0.61; 'first': 0.61; 'more': 0.64; 'different': 0.65; 'received:phx3.secureserver.net': 0.65; 'received:prod.phx3.secureserver.net': 0.65; 'when:': 0.68; 'e-mail,': 0.69; 'cut': 0.74; 'sole': 0.78; 'itself?': 0.84; 'preventing': 0.84; 'received:68.178.252': 0.84; 'way)': 0.84; 'apparent': 0.91; 'browsing': 0.91; 'disposal': 0.91; 'johnson,': 0.91; 'received:68.178': 0.91 |
| Date | Tue, 06 Jan 2015 19:37:40 -0800 |
| From | Andrew Robinson <andrew3@r3dsolutions.com> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Comparisons and sorting of a numeric class.... |
| References | <54ABB88A.7070504@r3dsolutions.com> <54ABC52A.1050507@davea.name> <54ABE383.3020801@r3dsolutions.com> <CAPTjJmpktyHfghEr+cjPrhso7JgB4VfS4=5Gdi95gT0aFbSYGA@mail.gmail.com> <54AC97D9.4010504@r3dsolutions.com> <CAPTjJmooTK_+HVoeyeSrqBHN1=YjRYQ2kfDyQtL9JoA9SbTqsQ@mail.gmail.com> |
| In-Reply-To | <CAPTjJmooTK_+HVoeyeSrqBHN1=YjRYQ2kfDyQtL9JoA9SbTqsQ@mail.gmail.com> |
| Content-Type | multipart/alternative; boundary="------------060701000205040205020209" |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.17429.1420601952.18130.python-list@python.org> (permalink) |
| Lines | 194 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1420601952 news.xs4all.nl 2835 [2001:888:2000:d::a6]:45000 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:83279 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On 01/06/2015 06:31 PM, Chris Angelico wrote: > >> The type check issue is mostly about compatability in the first place ; eg: >> users typecheck either unintentionally -- (novices syndrome) -- or because >> they need all the capabilities of a given type, and the only simple way to >> find out if they are all there are there is to typecheck. eg: That's the >> whole point of subclassing bool ... to let the user know they have at their >> disposal (in a portable, simple way) all the features of the base type. > Thing is, you're not fulfilling bool's contract, so it's better to not > subclass, and just make your new type always falsy. If your users are > type-checking bools, you might just have to let it break, and tell > them not to do that. > > ChrisA Explain; How does mere subclassing of bool break the contract that bool has? eg: What method or data would the superclass have that my subclass would not? Are you speaking about the quasi singleton nature of bool ? If so, I spent a little time browsing my design patterns book by Gamma, Helm, Johnson, and Vlissides; and I'm looking at the singleton pattern on p.127. The author writes, "Use the singleton pattern when: -- There must be exactly one instance of a class, and it must be accessible to clients from a well-known access point. -- When the _sole instance_ should be extensible by subclassing, and clients should be able to use an extended instance *without modifying their code*. " So, it's clear that in typical programming scenarios -- objects which are even more restrictive than bool by having only a single allowed instance rather than TWO -- are *Still* intentionally allowed to be subclassed for compatibility reasons. And later in design patterns, the authors continue on: "2. Subclassing the singleton class. The _main issue is not so much defining the subclass_ but installing its unique instance so that clients will be able to use it." So, the general programming community is aware of the issue Rossum brings up about a singleton's subclass having an instance; it's just apparent that there are ways to work around the issue and preserve a singleton's character while still allowing a subclass. So: I'm really curious -- If subclassing is generally permitted for singletons as an industrial practice, why is it wrong to allow it in python? I mean, If this is because Python doesn't support sub-classes for singletons, then it seems that Python is lacking something that should be added. This isn't limited to bool, for as a library writer I might want to create a singleton class for my own purposes that has nothing to do with any of python's built in types. And so, it would be appropriate to have a mechanism for subclassing user created singletons as well.... I already KNOW that 'C++' does have a workaround mechanism, as I've mentioned in a different e-mail, so that there's no reason to instantiate an instance of the subclass of a singleton if you don't want to. That objection is really spurrious... so I really don't understand why Rossum cut off subclassability itself ... wasn't there any other way he could have prevented instantiation of subclasses without preventing the definition of a subclass itself? I mean, even in python I can execute some methods of a class without actually INSTANTIATING that class. eg: import decimal decimal.getcontext() So, I don't understand your objection. How does merely defining a subclass of bool violate the contract that bool puts out?
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Comparisons and sorting of a numeric class.... Andrew Robinson <andrew3@r3dsolutions.com> - 2015-01-06 19:37 -0800
csiph-web