Python Debugging
COMP1312 - Programming I | L5.3
Overview
Debugging is the process of locating and removing errors from code. It works hand-in-hand with testing:
- Testing: Intent to show that a program has errors
- Debugging: Locate and fix the errors
<aside>
💡
Dijkstra's Quote
"If you want more effective programmers, you will discover that they should not waste their time debugging, they should not introduce the bugs to start with."
The best approach is to write high-quality code from the beginning, but debugging is inevitable in practice.
</aside>
Debugging Principles
Error-Locating Principles
1. Think First 🤔
- Review in your mind how the program is designed
- Understand how it should behave in the area performing incorrectly
- Trace the program flow from input to output mentally
- Identify where the error might occur
2. Describe the Problem to Someone Else 💬
- If you reach an impasse, explain your problem to another person
- This is what happens in labs with demonstrators and academics
- Often the act of explaining helps you see the issue