Read this: Global Variables Are Bad
Originally Posted by ulillillia
Unless you're using zero, this is probably not true.
I'm using as few as I can.
Image data and arrays don't get special status.
The bulk of the global variables is image data. These are in the form of arrays.
Good, so you got about 100 to 150 of the definitions correct.
About 100 to 150 of the others are actual variables, nearly all of which initialized.
This is also known as the "I'm too lazy to pass them" argument. Declare them locally, pass them to functions as needed. Group related stuff in structs if need be, to keep it manageable. At the very least, create a singleton object with global data inside that, so access to it is well controlled.
I use globals when multiple functions need to reference them.
Debugging is actually easier without globals, and conditional breakpoints work just as well, or better, when only using local variables.
I sometimes use it for debugging, for conditional breakpoints.
I'd be curious what other such cases are good cause to break one of the oldest tenets of good programming practice.
There are other such cases as well.
So you have 25% of your variables to move to local functions.
I've got about 3 times more local variables than I do globals.