Debugging: Dry Runs & Trace Tables 🐛
Welcome to this episode where we're tackling a crucial programming skill: debugging. Today, we're covering Period 23: Debugging Techniques, and our goal is to help you describe and exemplify dry runs and trace tables.
The Art of Finding Bugs
We'll start by defining debugging as the process of identifying and correcting different types of errors in code:
- Syntax errors (typos, incorrect grammar)
- Execution errors (run-time issues like dividing by zero)
- Logic errors (the code runs but doesn't produce the intended result). Our focus today is on logic errors, and we'll introduce two powerful techniques to find them.
First, we'll explain dry runs. A dry run is when you act as the computer, manually stepping through each line of your code to see what it does. This helps you understand the program's flow and logic.
Next, we'll introduce trace tables. A trace table is a more formal, systematic way to perform a dry run. It's a table used to record the value of each variable after every step of the program's execution. We'll emphasize their utility for pinpointing exactly where a variable's value changes incorrectly, leading to an error.
Hands-on Practice & Assessment ✍️
We'll work through two examples from "Trace Tables.docx". Example 1 will show a simple trace table with columns for num, num < 500, and OUTPUT. Example 2 will introduce a second variable, count, to demonstrate how trace tables can track multiple variables simultaneously.
You'll then apply these techniques to tasks from your booklet. You'll work on Task 10, Problem 1a and 1b from the "Software Design and Development Booklet v1.4.pdf" which focus on dry runs. Then, you'll tackle Task 10, Problem 2a and 2b which involve creating trace tables.
To help you, we'll provide pre-drawn trace tables and guide you through the first few steps of a more complex table. By the end of this episode, you'll be well-equipped to use dry runs and trace tables to diagnose and fix logic errors in your code.