I believe that the concept of failure . . . is central to understanding engineering, for engineering design has as its first and foremost objective the obviation of failure.
—Henry Petroski [Pe92]
This chapter views finding defects from the perspective of engineering. The first section of this chapter explains the worldview of the engineer. It suggests that engineering is about designing reliable structures and that the mindset of the engineer can be applied to the process of preventing and detecting bugs. It quotes several key statements from works by Henry Petroski [Pe92] and James L. Adams about the nature of the engineering process and relates them to the process of building and debugging software.
The second section of this chapter describes how programming errors can be classified by the development stage in which they occur. It proposes three stages of program development: conception, expression, and transcription. It defines each of these stages and provides lists of errors that are commonly committed during that stage.
The third section of this chapter describes how programming errors can be avoided according to the development stage in which they occur. It explains that there are two main ways to avoid conception-stage errors and shows how to use them. It continues by describing several ways to avoid expression-stage errors. It concludes by explaining several ways to avoid transcription-stage errors.
The fourth section of this chapter explains how to avoid programming errors by using coding conventions. It presents a general approach to programming conventions. It starts out with a general approach to object-oriented programming and structures a coding convention into six areas. For each of these areas, it recommends choosing a set of conventions that implement a set of metarules.
The fifth section of this chapter suggests adding debugging infrastructure to a program as it’s developed. It recommends the use of augmented data structures, augmented procedures, specialized debuggers, and assertions.