Carnegie Mellon University
Browse

Global variable considered harmful

journal contribution
posted on 1973-01-01, 00:00 authored by Wm. A. Wulf, Mary Shaw

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.

History

Publisher Statement

All Rights Reserved

Date

1973-01-01

Usage metrics

    Exports

    RefWorks
    BibTeX
    Ref. manager
    Endnote
    DataCite
    NLM
    DC