Get the latest tech news
Global variables are not the problem
In this article I'll show an example where avoiding a global variable has led to a bug, I'll define what global variables are, explain the problem, and then give examples where I have used them successfully. Global Variables Are Not the Problem We're all taught that global variables are bad.
They can be modified from anywhere, sometimes force functions to be called in a specific order, and can be impossible to debug if the program is large enough or the state is random enough. Such as a logger verbosity level, or a variable to enable recalculation of some data so we can detect if logic is wrong. Beginners might be lazy and use a global variable instead of changing the signature of a dozen functions, which blows up in their faces when they overwrite a value they need.
Or read this on Hacker News