> Why are globals considered bad? I'm seriously asking.
I think outside of special cases they bad. I use globals for embedded code because I don't have a heap.
What I've found is as long as globals are used to hold state and not pass data via spooky action at a distance they're okay. A test is if you can trivially refactor them out then they're okay.
Example you have one uart.
UartInit(baud_rate, bits, parity, stop);
Now you have two so gets refactored
UartInit(port, baud_rate, bits, parity, stop);
Terrible is shit code like this.
foo.bar = 2;
and somewhere else in the code
if(foo.bar == 2)
{
foo.bar = 0;
...
}
A note: Game programs to me look like really big embedded programs.
I think outside of special cases they bad. I use globals for embedded code because I don't have a heap.
What I've found is as long as globals are used to hold state and not pass data via spooky action at a distance they're okay. A test is if you can trivially refactor them out then they're okay.
Example you have one uart.
Now you have two so gets refactored Terrible is shit code like this. and somewhere else in the code A note: Game programs to me look like really big embedded programs.