Book Review: Find the Bug

Find the Bug: A Book of Incorrect Programs
by Adam Barr
Addison-Wesley, 2005
306 pages, $34.99
Code in C, Java, Python, Perl, and x86 assembler

No matter how sophisticated your software tools, finding the bugs in your code (and there will be bugs in your code, unless you're some hitherto-unknown specimen of programming supercritter) comes down to reading the source code and finding the bugs. The premise of this new book from Microsoft's Adam Barr is that one way to become better at finding bugs in source code is to read buggy source code and identify its problems. Thus, this book: a collection of fifty short programs (ten in each of the languages he uses), each with a single bug.

The buggy programs are grouped into chapters by language, and each language comes with a syntax review so that you can work with the programs even if that's not one of your core languages. For each program, Barr explains what it's meant to do, and then shows you the entire source code. Most of these are the sort of programming problems that you might ask a candidate to solve on a whiteboard during a job interview: make change for a dollar, compute a bowling score, provide a helper function for some game, and so on. After the source code, there are some suggestions of things to look for, and then some more blatant hints. Finally, Barr explains the bug in detail and offers a code fix.

Around the chapters of source code you'll find some motivational material on reading source code as well as a taxonomy of common types of bugs (though I suspect most programmers will find uncommon ways to insert bugs as well). The style is quite light and easy, and I had fun working through the code looking for the silly things other people did - and remembering equally silly things that I'd done myself.

In addition to honing your skills at finding your own bugs, this book has another valuable point: it can make you a better code reviewer. With all the techniques we have for helping make our code better, full source code reviews still stand out as one of the most valuable. But reviews are most useful if they're performed by people who look carefully at the code with an eye towards actually spotting logical errors, rather than checking for syntactical correctness (we have compilers for that). Go through these fifty exercises, and you'll be a better code reviewer. Your colleagues might not like that, but in the end the quality of your company's products will.

About the Author

Mike Gunderloy has been developing software for a quarter-century now, and writing about it for nearly as long. He walked away from a .NET development career in 2006 and has been a happy Rails user ever since. Mike blogs at A Fresh Cup.

Upcoming Events