Beginning tips for DebuggingΒΆ

Debugging a program is a different way of thinking than writing a program. The process of debugging is much more like being a detective. Here are a few rules to get you thinking about debugging.

  1. Everyone is a suspect (Except Python)! Its common for beginner programmers to blame Python, but that should be your last resort. Remember that Python has been used to solve CS1 level problems millions of times by millions of other programmers. So, Python is probably not the problem.

  2. Find clues. This is the biggest job of the detective and right now there are two important kinds of clues for you to understand.
    • Error Messages
    • Print Statements

There are also more advanced ways to debug a program. For example, later in the course you will learn about a module called pdb. It lets you set breakpoints in your code. Execution stops at each breakpoint and you can then inspect the value of variables and continue the execution. It’s a faster way to understand what’s going wrong than using print statements alone.

Next Section - Know your error Messages