After having worked with code that had made extensive use of Singletons, I think I would have to disagree. I'd say that Singletons have all of the advantages of global variables with all of the disadvantages of globals.
The only advantage I've seen is in grouping a set of variables (or behavior) into one Singleton object, instead of scattering them around. But, you can do that without Singletons, as well.
I try to avoid Singletons, because they've been the source of lots of trouble for me.
On the other hand, in a standalone script global variables can often simplify the code. The practice does tend to put an upper limit on how much the code can safely do.
|