How bad are globals, really??

Discussion about everything. New games, 3d math, development tips...
Post Reply
cartoonit
Posts: 286
Joined: Mon Nov 15, 2004 6:36 pm

How bad are globals, really??

Post by cartoonit »

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.
Munku
Posts: 66
Joined: Tue Nov 30, 2004 4:04 pm

Well

Post by Munku »

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.
Umm, don't look at me that way. I'M not the dead one here.

--The One True Marshmellow
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Globals aren't evil but it's a bad style of OO-programming.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Munku
Posts: 66
Joined: Tue Nov 30, 2004 4:04 pm

Oops

Post by Munku »

And bad for OO, too. Thanks for making me remember that simple fact, Bal.
Umm, don't look at me that way. I'M not the dead one here.

--The One True Marshmellow
Post Reply