Debugging Methods

Kernighan's advice might not be the last word. He said, Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

I like the quote because it frames the problem. But since we are often incented to work at our cognitive limits we benefit from catalog techniques that reduce this ratio. I will offer a few that work for me.

While coding:

1. read the diff before every commit. edit until the diff says what you thought you have been doing.

2. finish an episode of programming by inserting one print that shows your code working. If you can't, refactor.

While debugging:

3. use whatever variation of scientific method works for you. Here you trade time and rigor for brilliance.