1 Introduction

 

This chapter covers

  • The purpose and the structure of this book
  • Various techniques to improve the code quality
  • Advantages and disadvantages of static analysis
  • Approaches to make static analysis more useful
  • Testing and assertions

Every software developer introduces bugs to the code. There’s no way to avoid them completely. Some of the bugs cause very subtle change in program behavior and nobody cares about it. Other bugs may cost millions of dollars, lost spacecraft, or even human lives. Many of them are in the middle: they don’t have disastrous effects but they annoy users and require hours of debugging and fixing.

Some bugs are caused by misunderstanding of the specification requirements, miscommunication between the software development team and the customer, and so on. Another category of bugs comes from the miscommunication between the developer and the machine. That is: the developer correctly understands the problem but writes the wrong code, so the machine solves the problem incorrectly. This book is devoted to the latter category.

Some bugs are complex and unique. For example, one module may fail to handle a rare corner case, and another one may rely on that corner case. Everything was fine until these modules started talking to each other. In rare cases, three or more independent components are involved, and the problem appears only when all of them are connected to each other. Investigation of such problems can be as exciting as a good detective story.

1.1 The structure of this book

1.2 Code review and pair programming

1.3 Code style

1.4 Static analysis

1.4.1 Static analysis tools for Java

1.4.2 Using static analyzers

1.4.3 Limitations of static analysis

1.4.4 Suppressing unwanted warnings

1.5 Annotation packages

1.6 Dynamic analysis

1.7 Automated testing

1.8 Mutation coverage

1.9 Code assertions

1.10 Summary