Globals variables are like gum in your hair
Issue: 10.2 (January/February 2012)
Author: Jens Bendig
Article Description: No description available.
Article Length (in bytes): 11,136
Starting Page Number: 35
RBD Number: 10208
10208 project.zip Updated: Wednesday, January 4, 2012 at 2:54 PM
Related Link(s): None
Known Limitations: None
Excerpt of article text...
Good code is like a good haircut: it's clean, looks good, and is easy to maintain. But using global variables is like getting gum in your hair. The only way out is with scissors, and the end result is a completely different design.
We've known this for ages, but developers still try to ignore this fact. Maybe that's because global "gum" is so subtle—it gets in a little at a time and doesn't seem so bad at first, but eventually you have a sticky, unworkable mess.
Maybe it is just because developers—in the heat of coding—do not see other solutions for inter-object communication.
In this article I will not show how to completely avoid global variables. I will instead show you how to make them smarter... smart enough to cause fewer problems.
Why Not Use Global Variables?
Let me say it in a concise but abstract manner:
Every access to a variable has a _context_. Global variables deny that.
This denial-of-context is the way global gum works. It corrupts subtly from within.
...End of Excerpt. Please purchase the magazine to read the full article.
Article copyrighted by REALbasic Developer magazine. All rights reserved.