Give me ONE reason to use a singleton instead of a global variable/structure.
Name:
Anonymous2006-06-19 6:10
- global variables may have namespace collision when their programs are used as modules
- global variables are placed right next to executable code in memory and open up buffer-overflow vulnerabilites
- global variables violate the principle of information hiding and encourage the programmer not to perform sanity checks as there isn't just "one way" in and out of the variable (i.e., through an access function)
- global variables use up RAM the entire time the program is running
- global variables are for noobs
Name:
Anonymous2006-06-19 6:34
>>2 global variables may have namespace collision when their programs are used as modules
In most languages, global variables are module wise.
global variables are placed right next to executable code in memory and open up buffer-overflow vulnerabilites global variables use up RAM the entire time the program is running
That only happens if you are using a low-level language; and in that case the global variable may be just a reference or a pointer to circumvent this.
global variables violate the principle of information hiding and encourage the programmer not to perform sanity checks as there isn't just "one way" in and out of the variable (i.e., through an access function)
That only happens if your language fail. Yours seems to fail.
global variables are for noobs
Lol, gb2/java.net, you are the noob here.
Name:
Anonymous2006-06-19 8:26
In a multithreaded environment, you can put the mutex/semaphore/whatever code in the access method of the singleton, it's neater that way.
Name:
Anonymous2006-06-19 12:10
A singleton is OOP's answer to a global. If you use a lot of singletons in your code, you're an idiot.
1. Write a singleton that handles your global variable(s).
2. Convert the singleton to a namespace and hit yourself repeatedly for making it a singleton in the first place.
Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy