Debugging is about removing assumptions

Posted by james on Oct. 22, 2013

Debugging is about removing assumptions you've made. When a developer gets a ticket for a bug, they immediately start diagnosing what could be causing the problem. Then they are constrained by their own assumptions.

"This is failing on the server, but working on my computer. The code is exactly the same. This can't be happening."

"I ran this same SQL query on the test server, then ran it on the prod server. They should be exactly the same server version, but it says that a certain keyword is causing a syntax error."

In almost every case, the reason the dev can't find the problem is that they're making assumptions. Remove all assumptions.

"This is failing on the server (is it? Are you looking at the right site?), but working on my computer (is it? Did you rebuild the site? Did you paste the URL into your browser, forget to hit enter, and you're looking at old code?). The code is exactly the same (Did you forget to update your repo? Did you rebuild? Is the web server holding onto a cached copy?). This can't be happening (It is)."

But many devs don't start reaching into those assumptions and testing them. Test your assumptions. Try changing the connection string to the DB. Use a different browser, clear out cache first. Rebuild the site with a debug logging statement to see that you are definitely looking at the latest code. Intentionally add an error to make sure it actually fails in a way you can see. Start commenting out lines one at a time, especially the ones that you know for a fact are "safe". They're not.

It basically boils down to this: test, don't assume. If you *think* the code is the same, *test* that the code is the same. If you think that the server has the same version, then *test* that that's the case. There is no substitute for testing. Thinking very hard, remembering, assuming, guessing; those are all other ways of saying "not testing".