Debugging Tips

You have a BUG in your program!

  • If you find a bug,
  • Environment tips
  • Keep a debugging log or journal
  • General advice:

    Again, give yourself TIME to do this - debugging will take MORE time if you try to hurry. You run into a tough bug? look at everything you can about the problem, and then let it rest a while. Your subconscious can come up with new angles, sometimes a solution! if you let it work a while. Go take a walk, do some other homework, go clean something.

    Another tactic - take time to write down exactly what the bug seems to be doing - as clearly as you can, as precisely as you can. Or talk it out to someone who will listen (not recommended to be a student in the same class!) - talk to your cat! talk to Albert Einstein! A lot of times as soon as a student tells me what their problem is, they suddenly say "oh! never mind, I see it!"

    Try to focus on one bug at a time. Sometimes you can see evidence of more than one bug, and sometimes you can see the solutions to them all at once, or the solution to one is the solution to the other too. But a lot of times, you need to fix one bug before you can understand the other one. And as stated above, fixing one bug can uncover more.

    DON'T just "throw some code at it"! People do try random changes "maybe it should be 1 instead of 0" "maybe it should be less than instead of greater than"... Think first! The odds of fixing a bug correctly by just changing something without understanding what you're doing are very low!

    Sometimes the only solution to a bug is to toss out what you have and start over. If you peck away at code that isn't working and is badly designed, you WILL end up rewriting it - either with a fresh start, or a piece at a time. The experience you gained in the first attempt may be the difference that makes the second one work.