Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'none,': 0.07; 'tests.': 0.07; 'difference,': 0.09; 'immutable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '"is"': 0.16; "'is',": 0.16; 'argument,': 0.16; 'integers,': 0.16; 'integers.': 0.16; 'kern': 0.16; 'mutable': 0.16; 'preexisting': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'roy': 0.16; 'sense,': 0.16; 'sentinel': 0.16; 'singleton': 0.16; 'underlying': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'feb': 0.22; '>>>': 0.22; 'header :User-Agent:1': 0.23; 'circular': 0.24; 'integer': 0.24; 'interpret': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'chris': 0.29; "we'd": 0.29; 'am,': 0.29; 'robert': 0.30; 'code': 0.31; '13,': 0.31; '>>>>': 0.31; 'comparison': 0.31; 'convince': 0.31; 'encouraged': 0.31; 'equality': 0.31; 'though.': 0.31; 'tuples': 0.31; 'class': 0.32; 'fri,': 0.33; 'sense': 0.34; 'could': 0.34; 'test': 0.35; 'but': 0.35; 'there': 0.35; '14,': 0.36; 'returning': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'such': 0.63; 'our': 0.64; 'more': 0.64; 'world': 0.66; 'between': 0.67; 'believe': 0.68; 'optimized': 0.68; 'smith': 0.68; 'guaranteed': 0.75; 'article': 0.77; 'batchelder': 0.84; "class's": 0.84; 'eco': 0.84; 'optimized,': 0.84; 'terrible': 0.84; 'virtue': 0.84; 'received:86': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: singleton ... again Date: Thu, 13 Feb 2014 21:13:21 +0000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: cpc2-cmbg17-2-0-cust347.5-4.cable.virginm.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392326014 news.xs4all.nl 2868 [2001:888:2000:d::a6]:48400 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66244 On 2014-02-13 20:03, Chris Angelico wrote: > On Fri, Feb 14, 2014 at 2:24 AM, Roy Smith wrote: >> In article , >> Chris Angelico wrote: >> >>> On Thu, Feb 13, 2014 at 10:50 PM, Ned Batchelder >>> wrote: >>>> I still don't see it. To convince me that a singleton class makes sense, >>>> you'd have to explain why by virtue of the class's very nature, it never >>>> makes sense for there ever to be more than one of them. >>> >>> There's a huge difference, btw, between mutable and immutable >>> singletons. With immutables like None, True/False, integers, strings, >>> and tuples thereof, returning a preexisting object is just an >>> optimization. Do it if you want, don't if you don't, nobody's going to >>> hugely care. >> >> People *depend* on None being a singleton (and are encouraged to do so), >> when they use "is" as the test-for-Noneness. > > Circular argument, though. If None weren't a singleton, people would > use == to test for Noneness. Since it's been guaranteed to be > optimized to a singleton, the comparison can also be optimized, but > it's still just an optimization, as can be seen with integers. In > CPython, you could test for small integer equality using 'is', but > since that optimization isn't guaranteed, neither is that code > pattern. We don't use `is None` instead of `== None` for the speed. We use it for robustness. We don't want arbitrary __eq__()s to interfere with our sentinel tests. If None weren't a singleton that we could use as such a sentinel, we'd make one. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco