no singletons, please (was Re: an example Re: Connecting to running win32com server)

Glyph Lefkowitz glyph at no.spam
Thu Oct 12 15:51:57 EDT 2000


"Alex Martelli" <aleaxit at yahoo.com> writes:

> it's often best to *decouple identity and state*, by having
> many objects (different identities) *sharing state*, rather
> than trying to ensure the state-sharing happens through all
> object being one (having the same identity).

I'm not quite clear on what you mean by that.  Do you mean something like

class FooBar:
  MyState = {}

  def __init__(self):
    self.__dict__ = MyState

What good would that do?
  

> This applies to COM (in any language), but also outside of it.
> 
> "Same-Identity" can be a heavy burden to carry around when
> all one really wants to ensure is "Same-State"... which is
> most of the time when one starts thinking "Singleton"!

And besides, "singleton" is just the 90's way of saying "Global
Variable", since Global Variables are bad style for a variety of
reasons, but "Singleton" is a design pattern, and therefore must be
good... sheesh

When I have something that looks like a "singleton", I almost always
store it as a bunch of global state in the module that it's related to
rather than devoting a proper instance to it.

-- 
Glyph Lefkowitz
Professional -- Software Engineer,  Origin Systems
Amateur      -- Computer Scientist, Twisted Matrix Enterprises
(My opinions are my own and do not reflect in any way on the policies
or practices of my employer, etcetera etcetera.)



More information about the Python-list mailing list