Title

Global variable considered harmful

Date of Original Version

1973

Type

Working Paper

Rights Management

All Rights Reserved

Abstract or Description

In 1968 E.W. Dijkstra wrote a letter to the editor of the CACM proposing that the goto statement be abolished from all "higher level" programming languages. Although this suggestion has not met with universal acceptance, we would like to nominate another well-known language construct as a candidate for abolition: the non-local variable.
We claim that the noon-local variable is a major contributing factor in programs which are difficult to understand. For the moment we wish to keep the phrase "non-local variable" somewhat vague. Roughly, however, we mean any variable which is accessed, and particularly modified, over a relatively large span of program text. More specifically, we mean any variable are contained in S> We always intend conceptual locality, rather than textual locality; it may be the case that a single conceptual unit, (e.g., control of a loop) has elements that are separated by a number of lines of other text, but that the interpspresed text can be treated as a single element and "collapsed" for purposes of understanding the surrounding unit. If the text is properly displayed (e.g. with proper indentation), the physical distance between such elements need not interfere with their (conceptual) locality.