One principle that you have to keep all the time is “Cause-to-Effect”. Sherlock Holmes would be the greatest debugger if he lived in our computer age. He masters in reasoning skill, so that with a little scratch on a Dr. Watson’s shoe, he could entail back to Dr. Watson ran back to the house.
Debugging with “Cause-to-Effect” principle in mind leads to deduce from bulky erroneous code into few several error causing relevant lines. We recursively look code backward and keep asking “Who did it?” over and over. Then, we will eventually reach the root of error, the defect. Pex is an automated tool for checking corner cases. It injects possibly causing error inputs and show a result for each input. Double checking both by hands and by tools will give much confident that code is bug-free (just confident).
The line between root and cause is dependency. And, in programming, there are 2 types of dependencies:
- Data dependency
- Control dependency
These two are a compliment of each other. Control dependency makes data dependency events happen.
There is another fancy term for dependency in program debugging called “Splice”.
- Backward splice – what this code depends on
- Forward splice – what this code will affect to
One of tricks that eases debugging is “Dynamic slice”. Instead of looking into actual code, we look into actual execution. We usually call a record of execution as “Trace”. By considering only code that was executed, we can narrow down to parts that is relevant to make an error scenario. Then, We can track down from effect to cause with lesser effort.
An error may be influenced by many possible causes. We may spend much time on negative causes instead of fixing the actual cause. Therefore, it is by common sense that we go for the most likely origin of error. The lecturer gave a criteria on selecting which to go for first.
- Code Smell
- Bug History
- Last Changes
We can use “Delta Debugging” concept from the previous lecture to find the cause of an error. We inject value which causes an error to disappear. Then, we found root-to-cause chain of the error. But to be “Delta”, it has to be minimum change. It is one tick that vanishes the disaster.