Is this proverbially bad? What limitations does this have?
Global variables tend to impose a certain set of restrictions:
- they often don't clean up their resources properly
- are not thread safe (e.g. can be used from one thread or may introduce state per thread)
- they may not necessarily be safe to nest
- they can combat some of these problems by serializing requests -- introducing excessive suspension and locking.
- they become very difficult to 'extend' safely (i.e. adding global variables makes it more fragile)
- they are hard to test, and can lead to bugs which are very difficult to reproduce
What are the alternatives, and what is best?
Just move those variables to ivars, and create instances of the class rather than relying on global state. Then you can extend and abstract in a way which will not affect your clients significantly.
Note that static NSString* const url = @"http://local.namehidden.com:90/json.html";
would not be a mutable variable (added const
). So it's only _configData
and try
which would need to be ivars.