Chapter 10. Bug Hunting

If debugging is the process of removing software bugs, then programming must be the process of putting them in.

Edsger Dijkstra

It’s open season; a season that lasts all year round. There are no permits required, no restrictions levied. Grab yourself a shotgun and head out into the open software fields to root out those pesky varmints, the elusive bugs, and squash them, dead.

OK, reality is not as saccharin as that. But sometimes you end up working on code in which you swear the bugs are multiplying and ganging up on you. A shotgun is the only response.

The story is an old one, and it goes like this: Programmers write code. Programmers aren’t perfect. The programmer’s code isn’t perfect. It therefore doesn’t work perfectly the first time. So we have bugs.

If we bred better programmers we’d clearly breed better bugs. 

Some bugs are simple mistakes that are obvious to spot and easy to fix. When we encounter these, we are lucky.

The majority of bugs—the ones we invest hours of effort tracking down, losing our follicles and/or hair pigment in the search—are the nasty, subtle issues. These are the odd, surprising interactions; the unexpected consequences of our algorithms; the seemingly non-deterministic behaviour of software that looked so very simple. It can only have been infected by gremlins. 

This isn’t a problem limited to newbie programmers who don’t know any better. Experts are just as prone. The pioneers of our craft suffered; the eminent computer ...

Get Becoming a Better Programmer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.