Abstraction and a Single Point of Control

Just like editing papers, abstracting programs has many advantages. Creating an abstraction often simplifies other definitions. The process of abstracting may uncover problems with existing functions. But, the single-most important advantage of abstraction is that it creates a <#65528#><#29359#>SINGLE POINT OF CONTROL<#29359#><#65528#> for the functionality in a program. In other words, it puts the definitions (as much as possible) related to some specific task in one place. Putting the definitions for a specific task in one place makes it easier to maintain a program. Roughly put, program maintenance means fixing the program so that it functions properly in previously untested cases; extending the program so that it can deal with new or unforeseen situations; or changing the representation of some information as data (for example, calendar dates). With everything in one place, fixing an error means fixing it in one function, not four or five similar versions. Extending a function's capabilities, means fixing one function, not its related copies. And, changing a data representation means changing a general data-traversal function, not all those that came from the same template. Translated into a guideline, we say: rawhtml35 Guideline on Creating Abstractions rawhtml36 Form an abstraction instead of copying and modifying a piece of a program (for example, function, data definition). rawhtml37 Experience teaches us that maintaining software is expensive. Programmers can reduce the maintenance cost by organizing programs correctly. The first principle of function organization is to match the function's structure to the structure of its input data. If every programmer follows this rule, it is easy to modify and extend functions when the set of possible input data changes. The second principle is to introduce proper abstractions. Every abstracted function creates a single point of control for at least two different functions, often for several more. After we have abstracted, we often find more uses of the new function. Our design recipe for abstracting functions is the most basic tool to create abstractions. To use it requires practice. As we practice, we expand our capabilities for building and using abstractions. The best programmers are those who actively edit their program to build new abstractions so that they collect things related to a task at a single point. Here we use functional abstraction to study this practice. While not all languages provide the freedom to abstract functions as easily as Scheme, modern languages often support similar concepts and practicing in powerful languages like Scheme is the best possible perparation.