Teach students to use a system of inquiry, testing, and refining to debug their code, develop better coding habits, and deal with their frustration.

  • Students don’t always have a clear idea of where a bug originates or where to start debugging.
  • Trying to debug a program without a clear method or process for debugging can be overwhelming for students and function as a barrier to their success at debugging.
  • Use something like the following system of inquiry, testing and refining:
    • Inquiry: Have students try to reason about where the problem could be originating. This will depend on the specific code, but one way to guide this is to ask them if the first line of the program does what it should, and so on.
    • Testing: Once students have selected a part of the program, they can use print statements to print relevant variables to make sure the code is doing what it is supposed to be doing.
      • For example, if they choose a for loop that increments a variable five times, they can print the variable inside the for loop or outside to make sure it gets incremented five times.
    • Refining: Based on the results of testing, students should debug the piece of code they chose to test if they identify it as producing the bug. Otherwise students should move on to another piece of code, starting the process of inquiry, testing and refining again.
  • Students may be discouraged or frustrated by others who are able to find bugs quicker; however, it’s important that students learn that being able to find bugs comes with practice and experience.

More about this tip

External Source
Interview with Cynthia Lee