During the nearly 30 years that I have worked in software development, many aspects of the profession have changed. Languages have become popular and gone out of favor. Better development methodologies have been introduced, only to be replaced by yet more sophisticated methodologies. Microprocessors have become ubiquitous, and software has become the driving force behind many new products. The laptop computer that I wrote this book on has a faster processor, more memory, and more disk space than the multimillion dollar IBM(tm) mainframe on which I learned to program.
Some things have not changed, however. Software products still contain far too many bugs. Software developers still spend far too much time finding and fixing those bugs. People who are learning to program spend far too much time struggling to learn by trial and error.
I wrote this book because I wanted to introduce a systematic approach to debugging to a wide audience. If you learn something from this book that enables you to find and fix bugs more quickly, then I will have succeeded.
The case studies were done in C++ and Java because they were the most popular programming languages in use when this book was written. I refer to other popular languages, particularly C and Fortran, when they are relevant to a particular topic. Since this book focuses on how to think about debugging, rather than on specific platforms, almost all of the material is relevant to all programming languages. If your primary language is not Java or C++, you should still be able to apply at least 90 percent of the material in this book.
When the material in this book was presented in classes for computer science graduate students, I found a wide difference in which disciplines the students found most interesting or helpful. Some absolutely loved the analogy to detective literature. Others were uninterested. Some were fascinated by the study of human error. Others had trouble seeing how it was relevant to them. If you have problems relating to the analogy of one particular discipline, move on to another one, and come back later to the first one.
An undergraduate student who wants to develop debugging skills quickly should probably read chapters 1-4, 7-9, 5, 10, 11, and 15, in that order. Graduate students in computer science should add chapters 12-14 after that.
A professional programmer with years of experience may not feel the need to read the case studies (chapters 5 and 10). If you aren't sure whether a chapter will be of use to you, read the review at the end of the chapter first.
The material in chapters 6 and 12 is more theoretical than the rest of the book. Chapter 6 gives the rationale for the organization of chapters 7-9.
Chapter 12 applies ideas from cognitive psychology that attempt to explain how programmers create bugs.
Make sure that you read chapter 15, and make a plan for applying what you have read.
Boldface is used to introduce new terms, which are collected in the glossary, and to distinguish programming language keywords and commands from the text.
Example material that is computer generated, such as command-line entries and source code listings, is set in the following typeface:
This is a computer listing
Example material that isn't computer-generated, such as algorithm descriptions and debugging logs, is set in the following typeface.
This is a debugging log
Choosing the right third-person singular pronoun is a difficult task these days. In this book, unknown software developers are referred to as "he or she."
Thanks to Dr. Lawrence Rauchwerger, Dr. Nancy Amato, and their graduate students at Texas A&M University for giving me opportunities to present an early version of this material to them and for giving me valuable feedback on their classes.
Thanks to my managers at Hewlett-Packard, Betty van Houten, Steve Rowan, and Ty Rabe, who gave their permission for HP Press to publish this book.