Using Global Variables Essay
Sorry, but copying text is forbidden on this website!
Global variables are variables that are visible to every module in the program and its scope is the entire program so that all of the modules within the program can access a global variable. They can be declared in modules by simply setting up an assignment box and adding in the variables to the modules. In Pseudocode, you will simply write out the particular variable you want to declare and its value. Many programmers go against the idea of using global variables in modules but there are a few good sides to using global variables.
For one, the global variables are very easy to find within modules and can be accessed throughout all of them. Global variables also make it easier to update the objects code and on the APL*PLUS II/III systems, the correct signature in the first element can be installed once, and when the object is loaded into the workspace, instead of having to be done each time the FastFN is called.
It is suggested that you try to avoid using global variables when unnecessary for several reasons. Non-locality, in other words, source code is easy to understand when the scope of its individual elements is limited. Global variables can be read or modified by any part of the program, which makes it difficult to remember or reason about every possible use. Global variables also give no access or control or constraint checking. Global variables can be set by any part of the program, and any rules regarding its use can be easily broken or forgotten by extension, the lack of access control greatly hinders achieving security in situations where you may wish to run untrusted code. Global variables also lead to concurrency issues. If global variables can be accessed by multiple threads of execution, synchronization is necessary. When dynamically linking modules with globals, the composed system might not be thread-safe even if two independent modules tested in dozens of different contexts were safe. They also create Namespace pollution because the global names are everywhere. Memory allocation issues are also big when it comes to using global variables. Some environments have memory allocation schemes that make allocation of globals tricky.
Gaddis, T. (2010). Global Variables and Global Constants. Starting out with programming logic & design (pp. 104-105). Boston: Pearson Addison Wesley. Global Variables. (n.d.). Global Variables. Retrieved April 20, 2014, from http://www.chilton.com/~jimw/globals.html Global Variables Are Bad. (n.d.). Global Variables Are Bad. Retrieved April 21, 2014, from http://c2.com/cgi/wiki?GlobalVariablesAreBad Pros and Cons of Using Global Variables. (n.d.). Pros and Cons of Using Global Variables. Retrieved April 20, 2014, from http://social.msdn.microsoft.com/Forums/vstudio/en-US/53ae563a-bb7d-4526-b7c6-8e58c7bb62e6/pros-and-cons-of-using-global-variables?forum=csharpgeneral