According to Ed Yourdon, in the 1970’s global state was actually widely preferred over passing parameters to functions or subroutines.1 I had to laugh when I read the paragraphs on the most common objections, but this seems to have been a serious issue.
The objections listed are:
- Typing parameters means more typing, i.e. more work
- Getting the parameter list right is error-prone
- Accessing global state used to be more efficient
Yourdon dissipates the objections:
- Typing more parameters takes a bit of time now, but hunting bugs due to global state takes lots of time later.
- Errors in getting parameter lists rights are local and easily fixed; again, hunting bugs which appear because of global state involves way more detective work.
- Even in ‘79, machine time was less expensive than “people time”: hunting bugs isn’t worth the premature optimization.
But think about this for a moment. How spoilt we are using Xcode’s or any other IDE’s auto-completion feature to actually tell us parameter lists when we need them. Having to remember parameter lists and getting the sequence of unnamed parameters right was a problem sooooooo severe, people rather used global variables instead.
Crazy. Today people still have to be meticulously taught when and why global state causes trouble. In object-oriented programming, Singletons are the reincarnation of global state.