OK, not a complete guide to all debugging.
But just a few tricks I regularly use.
Consider when you are debugging a program that already exists but is not doing what you want:
Sample code I give you in a lab that you have to modify.
Sample code from the Internet.
AI generated code.
I have noticed students often do not have the right mindset for finding what is wrong.
Here are a few simple tricks for how to debug a program:
Strip it down. Remove parts of it.
Get smaller parts working first.
Don't try to do it all at once.
You don't have to delete code. Just comment it out. Then slowly comment it back in.
Comment out lines of code:
# code
// code
A trick is to use tabs to make it easy to comment code out and in:
# code
# code
code
# code
Comment out blocks of code:
/*
code
code
*/
Insert an exit after reaching a certain stage
(comments out everything below it):
code
code
exit
code
code
Look at variables half-way through:
echo $var
System.out.print(var);
console.log(var);
Build all programs in stages, testing each stage.
Slowly comment code back in.
Slowly move exit further down
or remove it.
Slowly remove debug info.
Debugging
is not a mystery.
Yes, there are fancy debugging and tracing tools.
But half the time, a few well-chosen prints, exits and comment-outs
are all you need
to find the problem.