Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Add a Borg class? #22
Comments
|
Cool hack, but useless? Defeats using At least to me, one of the main use cases of a singleton in Python is a stateless, unique marker value, which can be identified with a quick object identity check ( (Lispy symbols can be used as sentinel values, but a singleton may be better if the object needs to have some functionality beside just being a marker. For example, In Python, the constructor syntax issue for singletons is a herring, because Since modules are effectively singletons already, for any object type that is to be a singleton, in my opinion The Pythonic Thing is to make the constructor raise It is trivial to grab a reference from the top-level scope of another module, thus performing the job of the singleton instance accessor (as seen in static languages). Also, guaranteeing that the instance has been created before any other module tries to access it is trivial (modulo any circular imports). We now have such a pythonified, thread-safe singleton abstraction as We now also have lispy, interned, named symbols with a similar level of Since I can't think of a use case that If a reason to use a |
A cool hack from ActiveState recipes. Different instances, all sharing the same state.
OTOH, it's really simple and already documented in the ActiveState recipes, so maybe we don't need to have it here.