I have seen peoples discussions about it before, and been involved in discussions regarding globals with other colleagues. Are globals really as horrendous as everyone makes out them to be?? I understand about the possibility of them becomimg over-ridden by data, and how hard they can become to debug.
I have looked at other ways in which you could combat a global, such as passing it in to a function when you specifically need it. Using a singleton, seems an appropriate method to encapsulate a global. But it also means you have to inherit this singleton with every class you want to use your global with. This seems a little constrictive as to the portability of seperate classes you then build, because you require the singleton everytime you require the global.
I was going to go on a long rant, but I've had enough of long ranting today!!
Just wanted to get other peoples opinions of what they think and other solutions, apart from the following: a singleton, a global, or inheriting from a base class everytime you require a single instance of a variable.
How bad are globals, really??
Well
Waaaaaayyyyy back when the computers were not even close to the gigahertz range globals were best because even though they took up alot of memory. Globals may speed things up even now, though I don't think the speed increase would be anything spectacular. I don't believe you need too many globals, though some are quite usefull.
My current global list
A boolean for the game mode, sub game mode and wether the game is running.
The Camera (just for ease of use)
That's about all. I have been thinking, however, to make my CEngine (the main class) global...but in reality...I don't have to.
Basically now adays, to save memory, using globals are not all that usefull on the whole--however, I don't see anything terribly bad about it....just clean them up if you need to afterwards.
My current global list
A boolean for the game mode, sub game mode and wether the game is running.
The Camera (just for ease of use)
That's about all. I have been thinking, however, to make my CEngine (the main class) global...but in reality...I don't have to.
Basically now adays, to save memory, using globals are not all that usefull on the whole--however, I don't see anything terribly bad about it....just clean them up if you need to afterwards.
Umm, don't look at me that way. I'M not the dead one here.
--The One True Marshmellow
--The One True Marshmellow