Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'represents': 0.05; 'column': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'handful': 0.09; 'message-id:@stoneleaf.us': 0.09; 'rows': 0.09; '~ethan~': 0.09; 'class:': 0.16; 'enum': 0.16; 'finney': 0.16; 'it;': 0.16; 'namespace,': 0.16; 'received:69.93': 0.16; 'received:gateway01.websitewelcome.com': 0.16; 'roy': 0.16; 'sense,': 0.16; 'singleton': 0.16; ':-)': 0.16; 'language': 0.16; 'wrote:': 0.18; 'module': 0.19; 'trying': 0.19; '>>>': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'looks': 0.24; "i've": 0.25; 'values': 0.27; 'van': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'am,': 0.29; '(like': 0.30; '>>>>': 0.31; 'convince': 0.31; 'writes:': 0.31; 'class': 0.32; 'computer.': 0.33; 'third': 0.33; 'sense': 0.34; 'hundreds': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; "he's": 0.36; 'useful': 0.36; 'should': 0.36; 'implement': 0.38; 'ben': 0.38; 'to:addr:python- list': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'received:173': 0.61; "you're": 0.61; 'more': 0.64; 'skip:\xe2 10': 0.65; 'effectively': 0.66; '8bit%:40': 0.68; 'smith': 0.68; 'serial': 0.72; '4:00': 0.84; 'batchelder': 0.84; "class's": 0.84; 'enumeration,': 0.84; 'virtue': 0.84; 'ports': 0.93 Date: Thu, 13 Feb 2014 08:57:50 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: singleton ... again References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3304.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source-IP: 173.12.184.233 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([173.12.184.233]) [173.12.184.233]:32996 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 1 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3IzMzA0Lmhvc3RnYXRvci5jb20= 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392313443 news.xs4all.nl 2885 [2001:888:2000:d::a6]:54125 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66194 On 02/13/2014 03:50 AM, Ned Batchelder wrote: > On 2/13/14 4:00 AM, Piet van Oostrum wrote: >> Ben Finney writes: >> >>> Gregory Ewing writes: >>> >>>> Roy Smith wrote: >>>>> It looks to me like he's trying to implement a classic Gang of Four >>>>> singleton pattern. >>>> >>>> Which I've never really seen the point of in Python, or any other >>>> language for that matter. Just create one instance of the class during >>>> initialisation, put it in a global somewhere, and use it thereafter. >>> >>> Make that “somewhere” a module namespace, and you effectively have a >>> Singleton for all practical purposes. So yes, I see the point of it; but >>> we already have it built in :-) >> >> There is a use case for a singleton class: when creating the singleton >> object takes considerable resources and you don't need it always in your >> program. >> > > 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. Say you have a database with a column that can only have a handful of values (like an enumeration, for instance) and this database can have hundreds of thousands of rows. When you're working with all those rows at once having just one object for the third enum value is a useful optimization. Say you have a class that represents serial ports or your computer. You should get the same object every time you ask for SerialPort(2). -- ~Ethan~