[comp.object] Global state -- a villain?

lpd@aladdin.com (L. Peter Deutsch) (01/04/91)

In-reply-to: gudeman@cs.arizona.edu's message of 3 Jan 91 07:04:24 GMT
Newsgroups: comp.object
Followup-To: comp.object
Subject: Re: Global program state.
References: <330@coatimundi.cs.arizona.edu>
Distribution: 

In article <330@coatimundi.cs.arizona.edu> gudeman@cs.arizona.edu (David Gudeman) writes:


   In article  <27823155.211e@petunia.CalPoly.EDU> John R. Dudeck writes:
   ]
   ]In the book, _Principles of Functional Programming_, by Glaser, Hankin,
   ]& Till, it is stated, "the notion of global state that may change
   ]arbitrarily at each step of the computation has proved to be both
   ]intuitively and mathematically intractable."

   That is something of an exaggeration.  The mathematics of global
   states is almost trivial compared to the mathematics of recursive
   functions.

Well, I suppose that is a matter of opinion.  The formal handling of global
state is pretty trivial, but when you try to reason about programs, global
state and uncontrolled side-effects cause (in my experience) many more
headaches than recursive functions.

   It's hard to argue the "intuitive tractability" of global states, but
   clearly the thousands (millions?) of working programs written under
   the notion of a global state might be considered a counter-example to
   the claim.

A great many of the so-called "working programs" have bugs, some of
them serious, and a great many of them traceable directly to the
issue of global state.  Having written tens if not hundreds of
thousands of lines of "working" :-) code myself, I believe that
success is strongly correlated with my ability to organize the
program in such a way that the notion of global state is minimized or
entirely eliminated, i.e., with being able to segment the state into
conceptually distinguishable parts that obey well-defined invariants
within themselves and interact with other parts only in narrow ways.
I.e., the villain is not global MUTABLE STATE, but GLOBAL mutable
state.  Object-oriented organization is (in my opinion) the best set
of rules discovered so far for helping carry out this segmenting
process.