Global Variables Are Evil

Global variables are evil because they can be accessed / modified from any functions. This make every function potentially dangerous.

If you are the only developer for the product, then global variables may be acceptable (you should still keep them to a minimal), but how often is this the case. In real world scenarios, developers come and go. If you don't keep an eye on global variables (document all the global variables that you use), you will quickly forget about them. If you have a new team member, you may forget to train him and let him know about the global variables that you have.

http://www.svennerberg.com/2009/02/global-variables-in-javascript/
http://www.nczonline.net/blog/2006/06/05/global-variables-are-evil/
http://ubuntuforums.org/showthread.php?t=658778
http://www.yuiblog.com/blog/2006/06/01/global-domination/
http://www.learncpp.com/cpp-tutorial/42-global-variables/

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License