Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1a.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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'none,': 0.07; 'difference,': 0.09; 'immutable': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'functions;': 0.16; 'imo,': 0.16; 'integers,': 0.16; 'mutable': 0.16; 'preexisting': 0.16; 'sense,': 0.16; 'singleton': 0.16; 'wrote:': 0.18; 'module': 0.19; 'thu,': 0.19; 'feb': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'affects': 0.24; 'cc:2**0': 0.24; 'least': 0.26; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'gives': 0.31; '13,': 0.31; 'convince': 0.31; 'tuples': 0.31; 'class': 0.32; 'another': 0.32; 'programmers': 0.33; 'sense': 0.34; 'connection': 0.35; 'created': 0.35; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'module.': 0.36; 'object,': 0.36; 'returning': 0.36; 'should': 0.36; 'pm,': 0.38; 'explain': 0.39; 'back': 0.62; 'more': 0.64; 'between': 0.67; 'other.': 0.75; 'batchelder': 0.84; "class's": 0.84; 'different.': 0.84; 'virtue': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=gOoFHHVIKHNfKK0YCHupKDxt3/ZO7B5rQWc4WcKNSM8=; b=XGf2FOfBqDSePAwqf5HDisGI2JI14Ehvb/J7lD9dOye7NNGpZQnGSDP73yB1sKVW7C ahJ9Cy8kfSOmMYPIKHzoFPF2y2GlfkvtWcyFryv1CNVyY5HLtccWtUmq+TtKR5U2oD3L NQZ2K/gfblEXuyFtdiWJ/lH9Dj3PUbRNlFgh5JTHgtkwZYGbXPmxP6YCdWczkM4Sc7/h o3um14KUITJ4HRBwqxogNqfba9GRYsh9PpPkvr3FwsTFiRR3D58XcMWePskYpUBpWS7V JFzDDkn8/HYeWKVJ5fvxDhZzl7AXQMo7vufb3Hsm3vHUh740FyFTZ0RDmInsG7UGsKeX pYcg== MIME-Version: 1.0 X-Received: by 10.66.26.176 with SMTP id m16mr1268663pag.142.1392292642996; Thu, 13 Feb 2014 03:57:22 -0800 (PST) In-Reply-To: References: Date: Thu, 13 Feb 2014 22:57:22 +1100 Subject: Re: singleton ... again From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392292646 news.xs4all.nl 2944 [2001:888:2000:d::a6]:59391 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66170 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. With mutables, it's hugely different. A singleton "database connection" object would, imo, be hugely confusing; you'd think you created a separate connection object, but no, what you do on this one affects the other. Better there to have module-level functions; at least Python programmers should understand that reimporting a module gives you back another reference to the same module. ChrisA