News for hackers. Stuff that matters.
Re:Singleton Is a Bad Idea by kstenerud on Sunday April 10, 2022 @02:30PM (#30980137)
Singleton is a trick to get around problems in "everything is an object" languages. It's a hack to store global data, just like the alternatives shown in this article.

If you need globals and your language supports global data or functions, use that. If not, Singleton is a viable alternative.

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.
Re:Singleton Is a Bad Idea by nedbat on Sunday April 10, 2022 @03:19PM (#30980682)
You make it sound like "everything is an object" also means "there are no globals". What language is like that?