next up previous
Next: 2.1.4.5 The Iterator Pattern Up: 2.1.4 Mutable Sequences Previous: 2.1.4.3 Nested Classes vs.

2.1.4.4 Spaghetti References (akin to spaghetti code)

We adopt the slogan "pointers are the root of all evil." In the 1970s, structured programming was developed, which placed a discipline on the control flow of programs. Up until that point, languages (and programmers) had been very liberal in their use of the notorious goto statement, also known as the unconditional branch. Undisciplined use of this feature leads to programs whose control flow is almost impossible to trace by hand (spaghetti code), and which are hence almost impossible to debug. In his Turing Award Lecture in the early 1970s, C.A.R. Hoare asserted that multiple references to the same data in a program can contribute a similar kind of complexity, especially if the data can be mutated through those references. With multiple references to mutable data in a program, we can stumble into serious trouble when one part of our program modifies an object when another part is unaware of or unprepared for the modification.

Even in programs written and maintained by a single programmer, the unrestricted use of pointers is foolhardy and invites disaster. A programmer almost certainly does not remember the precise reasoning used involved in writing every section of a significant application. As a result, mistakes are inevitable. Just as structured programming placed constraints on the control flow in programs, we will place constraints on when and where mutable data can be changed. This is why we hide mutable nodes inside a list container.


next up previous
Next: 2.1.4.5 The Iterator Pattern Up: 2.1.4 Mutable Sequences Previous: 2.1.4.3 Nested Classes vs.
Corky Cartwright
2000-01-07