Re:Singleton Is a Bad Idea
by TheOtherHobbes on Sunday April 10, 2022 @03:14PM
(#30980637)
Although it can be hacky to implement in Python, a singleton object can enforce locking and privilege-based access control. It can also group globals into sub-objects, which can make some naming systems easier to enforce/remember.
Open globals are unstructured, and more likely to turn into a messy free for all.
Re:Singleton Is a Bad Idea
by Traubenfuchs on Sunday April 10, 2022 @02:34PM
(#30980191)
> It's a hack to store global data
* It's a solution to store, encapsulate and abstract global data
Re:Singleton Is a Bad Idea
by humanrebar on Sunday April 10, 2022 @03:06PM
(#30980550)
Eh. Global data doesn't really get abstracted. Abstractions over global data generally leak like a sieve.
If you need globals and your language supports global data or functions, use that. If not, Singleton is a viable alternative.