Saturday, November 22, 2008

The No-Output Debugging Technique

I run into this situation now and then by accident. If I could just figure out how to bottle it, all the world's software problems would be solved!

Here's the scenario:

- Notice a slight bug in some program output (typically a web page).
- Make the obvious code change, reload the page, bug is still there.
- Make more aggressive code change, making code more modular. Still no dice.
- Add several assertions, improve default assignments. Make control flow easier to follow. Comment the heck out of everything. Still the same bad output.
- Put in some impossible-to-ignore condition: remove the procedure, or always raise an exception, or print some big banner with debug info. Still the same page as before!
- Notice I'm loading the production version of the page instead of the test version. Try the right version with the updated code. Bug was fixed by very first edit.

This is a great way to trick yourself into writing better code.


dara said...

i usually make my test page use a different CSS, eg. one with pink background. ever since, i did not run into this mistake. but then i have to maintain a different css. in my opinion, it's worth it.

Brian Tkatch said...

Been there, done that.

One thing to do is remove the page and see if it makes a difference. Simple sanity check.

John Russell said...

This has happened to me often enough that I have all these workaround tips in mind... but the amount of improvement in the code when it happens makes me want to leave the possibility open..