python-novice-inflammation icon indicating copy to clipboard operation
python-novice-inflammation copied to clipboard

Add some clarity and a brief example to the 'make it fail every time' segment of the 'Debugging' lesson

Open AndrewGibbs opened this issue 2 years ago • 0 comments

I find most of the description on this page very clear and well-written. However, in the make it fail every time segment of the debugging lesson, I found the text to be unclear, and the strategy for finding the bug to be too general for a beginner to understand. I propose that an example is briefly described (not coded), to clarify the concept.

Based on my programming experience, the current general solution given in the text may be referring to either one of the following two cases:

  1. Code which contains a random element. For example a diffusion model which contains some random walk. In such a case, the same input parameters can be used twice, to obtain a different output in both cases. And within the code, certain random values will produce unexpected results.
  2. Code with no random element, which is being tested over a wide range of input parameters, and fails for at least one input being tested. For example, code to compute f(x)=sin(x)/x, tested for x=-10,-9,-8,...,8,9,10, may produce a zero/zero error when x=0, even though the desired output might be f(0)=1 (see here).

It is not clear to me if the original author had either one of these two cases in mind. To add some clarity, I think that either of these could be included as an example. Including both would be too much extra material. In each case a different strategy would be required to make it fail every time.

  • In case one, a sensible solution would be to temporarily modify the code to print the random values used after they are computed, and note down some of the random values which breaks the code. Then, the user should temporarily hard code the random value to the one which is known to break the code, while they look for the problem.
  • In case two, it is appropriate to modify the test code, to record input parameter(s) which give unexpected results. Then a single parameter can be investigated specifically.

Personally, I think the first example and solution is the more interesting of the two choices.

AndrewGibbs avatar Nov 05 '21 16:11 AndrewGibbs