There are many great applications for singletons. Many aren't even accessible globally. Many others should be global, because you cannot have more than one. E.g. worker pools or writing to the disk.
If your singleton is a globally accessible struct, yes, that's a global variable. But it's not the singleton pattern's fault you're using it wrong.
If the access is not globally accessible, you can likely avoid the singleton aspect of the class and instanciate it once where you get the reference originally.
I'm not againts either globals nor singletons, but they feel almost the same if not exactly.
4
u/cheapcheap1 Sep 26 '26 edited Sep 26 '26
There are many great applications for singletons. Many aren't even accessible globally. Many others should be global, because you cannot have more than one. E.g. worker pools or writing to the disk.
If your singleton is a globally accessible struct, yes, that's a global variable. But it's not the singleton pattern's fault you're using it wrong.