next up previous
Next: The Iterator Pattern Up: Extended Mutable Lists Previous: Formulating Traditional Linked Lists

Spaghetti References (akin to spaghetti code)

We strongly endorse 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 or unconditional branch. Undisciplined use of goto statements 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 introduce a similar form of complexity if that 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: The Iterator Pattern Up: Extended Mutable Lists Previous: Formulating Traditional Linked Lists
Corky Cartwright 2004-02-05