http://www.perlmonks.org?node_id=76191


in reply to Are debugging skills atrophying?

Didn't we do a debugging thread here a while back? Might be worth it to check.

In any event, I think the most important thing I learned in my 28 years of programming is "debugging is hard". So I spend nearly every moment of my time while I'm programming thinking about how not to put bugs in in the first place, or at least have a pretty good idea what I just broke on the last edit cycle.

My methodology is basically:

  1. Start with an empty file.
  2. Write a dozen lines of code
  3. Run it
  4. If that doesn't work, add a few warn statements until I see what I broke, and fix it.
  5. Add another dozen lines of code. Repeat.
The key seems to be small incremental progress. Note that this methodology works for command-line, CGI, and whatever. Always have a testable version that's no more than a dozen lines different from the one you're working on. Then you'll know your error is always within the last dozen lines of code you wrote.

Another element is "understand what you type". You should be able to have a complete mental model of every step of what you type. Yeah, it sounds so basic, but I'm amazed when I watch my students copy random lines of code into their program and then say "it didn't work". When I ask them what a particular line does, they say "I don't know". Gosh, how do they expect it to work then!?

So maybe the combined rule is "never type faster than you can understand". {grin}

-- Randal L. Schwartz, Perl hacker