Simple debugging tricks and techniques
We saw the power of the simple print
statement in the previous example. In a similar way, other simple techniques can be used to debug programs without requiring to resort to a debugger.
Debugging can be thought of as a step-wise process of exclusion until the programmer arrives at the truth—the cause of the bug. It essentially involves the following steps:
Analyze the code and come up with a set of probable assumptions (causes) that may be the source of the bug.
Test out each of the assumptions one by one by using appropriate debugging techniques.
At every step of the test, you either arrive at the source of the bug—as the test succeeds telling you the problem was with the specific cause you were testing for; or the test fails and you move on to test the next assumption.
You repeat the last step until you either arrive at the cause or you discard the current set of probable assumptions. Then you restart the entire cycle until you (hopefully) find the cause...