Why global variables are evil?

May 21, 2013 at 8:47pm
I've seen numerous people state that global variables are evil while I came across some libraries depend heavily on them. I assume in my question that the programmer knows what he/she is doing.
May 21, 2013 at 9:07pm
Its a matter of control. Who can modify a global? What is the lifetime of the global? What if I want to go parallel? Globals are like cats; they may look cute, but will they do your bidding easily or at all?
May 21, 2013 at 11:32pm
@keskiverto,
So based on my assumption and your answer, they are not evil. Am I right?
May 22, 2013 at 5:03am
If the purpose of a variable is to be continuously modified in many places by the user such as std::cout or std::cin, then making the variable global seems reasonable. Here are some links for more info. For the most part, your variables are probably only going to be managed by a few functions that can easily be wrapped in a class or by passing as parameters.

http://stackoverflow.com/questions/484635/are-global-variables-bad
http://www.learncpp.com/cpp-tutorial/42-global-variables/
May 25, 2013 at 12:49am
@Daleth,
Thank you for these links. They are very good especially the second one.
Topic archived. No new replies allowed.