I keep reading that using global variables is bad programming design, but does that mean global constants are also bad?
What alternatives are there instead of global variables/constants and what’s the best way to declare constants that’s needed in multiple source files ?
The primary reason behind global variables being bad is reliance of shared state, which makes it easy for different parts of a program to cause unanticipated interference with other parts of the program by manipulating the shared state in ways that you did not intend to, making the program more error prone, hard to debug, and hard to maintain.
Constants, on the other hand, are pretty much okay, except for the fact that they pollute the global namespace (which might cause unintended consequences at compile time by changing the meaning of a symbol in the compilation unit). If you can declare them in a specific namespace/scope, then you’re going to be fine.