Debugging and Problem Solving
When programs go wrong
What is a bug?
A bug is an error in a program that causes it to behave incorrectly. Debugging is the process of finding and fixing bugs.
A simple debugging process
-
1
Step 1: Observe the wrong behavior.
-
2
Step 2: Form a guess about the cause.
-
3
Step 3: Test the guess and change the code if needed.
Bugs are normal
Every programmer makes mistakes. Debugging is a normal and important part of programming.
What does debugging mean?
Debugging is the process of correcting bugs.
Correct answer: Finding and fixing program errors
What is a bug?
A bug causes a program to act differently from what was intended.
Correct answer: An error in a program
Common debugging habits
Useful habits include reading code carefully, checking one change at a time, using examples, and asking what the program was supposed to do.
Which is a good debugging habit?
Testing one change at a time helps identify the real cause.
Correct answer: Test one idea at a time
Why is it helpful to test one change at a time?
Small controlled changes make debugging clearer.
Correct answer: It makes it easier to know which change fixed the problem