Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66194

Re: singleton ... again

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 <ethan@stoneleaf.us>
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 <ethan@stoneleaf.us>
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 <fdbb58a7-87c0-4a2f-bedf-f8e3e14fa356@googlegroups.com> <mailman.6728.1392183929.18130.python-list@python.org> <roy-11BAB5.00555912022014@news.panix.com> <bm0v9iFpuquU1@mid.individual.net> <mailman.6750.1392199807.18130.python-list@python.org> <m2a9dvmlos.fsf@cochabamba.vanoostrum.org> <ldibhu$2g5$1@ger.gmane.org>
In-Reply-To <ldibhu$2g5$1@ger.gmane.org>
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 <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.6850.1392313443.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


On 02/13/2014 03:50 AM, Ned Batchelder wrote:
> On 2/13/14 4:00 AM, Piet van Oostrum wrote:
>> Ben Finney <ben+python@benfinney.id.au> writes:
>>
>>> Gregory Ewing <greg.ewing@canterbury.ac.nz> 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~

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

singleton ... again Asaf Las <roegltd@gmail.com> - 2014-02-11 20:34 -0800
  Re: singleton ... again Asaf Las <roegltd@gmail.com> - 2014-02-11 21:15 -0800
  Re:singleton ... again Dave Angel <davea@davea.name> - 2014-02-12 00:48 -0500
    Re: singleton ... again Roy Smith <roy@panix.com> - 2014-02-12 00:55 -0500
      Re: singleton ... again Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-12 23:04 +1300
        Re: singleton ... again Ben Finney <ben+python@benfinney.id.au> - 2014-02-12 21:09 +1100
          Re: singleton ... again Roy Smith <roy@panix.com> - 2014-02-12 08:40 -0500
          Re: singleton ... again Piet van Oostrum <piet@vanoostrum.org> - 2014-02-13 10:00 +0100
            Re: singleton ... again Ned Batchelder <ned@nedbatchelder.com> - 2014-02-13 06:50 -0500
            Re: singleton ... again Chris Angelico <rosuav@gmail.com> - 2014-02-13 22:57 +1100
              Re: singleton ... again Roy Smith <roy@panix.com> - 2014-02-13 10:24 -0500
                Re: singleton ... again Chris Angelico <rosuav@gmail.com> - 2014-02-14 07:03 +1100
                Re: singleton ... again Robert Kern <robert.kern@gmail.com> - 2014-02-13 21:13 +0000
                Re: singleton ... again Chris Angelico <rosuav@gmail.com> - 2014-02-14 08:27 +1100
            Re: singleton ... again Ethan Furman <ethan@stoneleaf.us> - 2014-02-13 08:57 -0800
              Re: singleton ... again Roy Smith <roy@panix.com> - 2014-02-13 12:57 -0500
                Re: singleton ... again Ethan Furman <ethan@stoneleaf.us> - 2014-02-13 10:31 -0800
                Re: singleton ... again Roy Smith <roy@panix.com> - 2014-02-13 14:03 -0500
                Re: singleton ... again Chris Angelico <rosuav@gmail.com> - 2014-02-14 06:50 +1100
                Re: singleton ... again Grant Edwards <invalid@invalid.invalid> - 2014-02-13 22:28 +0000
              Re: singleton ... again Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-14 18:21 +1300
            Re: singleton ... again Tim Delaney <timothy.c.delaney@gmail.com> - 2014-02-14 06:16 +1100
        Re: singleton ... again Steven D'Aprano <steve@pearwood.info> - 2014-02-13 02:58 +0000
          Re: singleton ... again Ben Finney <ben+python@benfinney.id.au> - 2014-02-13 14:07 +1100
            Re: singleton ... again Steven D'Aprano <steve@pearwood.info> - 2014-02-13 04:24 +0000
              Re: singleton ... again Chris Angelico <rosuav@gmail.com> - 2014-02-13 15:33 +1100
              Re: singleton ... again Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-14 18:15 +1300
          Re: singleton ... again Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-14 18:06 +1300
    Re: singleton ... again Asaf Las <roegltd@gmail.com> - 2014-02-12 09:50 -0800
      Re: singleton ... again Asaf Las <roegltd@gmail.com> - 2014-02-12 09:56 -0800
        Re: singleton ... again Asaf Las <roegltd@gmail.com> - 2014-02-12 09:58 -0800
        Re: singleton ... again Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-13 10:57 +1300
          Re: singleton ... again Asaf Las <roegltd@gmail.com> - 2014-02-12 17:38 -0800
      Re: singleton ... again Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-12 18:57 +0000
        Re: singleton ... again Asaf Las <roegltd@gmail.com> - 2014-02-12 17:02 -0800
      Re: singleton ... again Ned Batchelder <ned@nedbatchelder.com> - 2014-02-12 16:34 -0500
        Re: singleton ... again Asaf Las <roegltd@gmail.com> - 2014-02-12 17:34 -0800
      Re: singleton ... again Tim Delaney <timothy.c.delaney@gmail.com> - 2014-02-13 10:08 +1100
      Re: singleton ... again Roy Smith <roy@panix.com> - 2014-02-12 20:57 -0500
  Re: singleton ... again Michael Torrie <torriem@gmail.com> - 2014-02-12 15:05 -0700

csiph-web