The Craft Of Coding

CPP 14 Mar Debugging

Posted by Pete Tue, 08 Mar 2016 04:00:00 GMT

Debugging

In order to do a good job in debugging, your first need some good test cases and the expected outputs. Make sure that your sample TestScores.txt are set up so the expected numbers in the QuizReport.txt are easy to confirm.

  • When using debugging outputs, make sure that you do not produce so much output that you cannot see what is happening.
  • Put in ONE debugging output to confirm or reject a SINGLE prediction about the code, then run the program to find out if your prediction is correct. This is sometimes known as Scientific Debugging
  • After your prediction has been confirmed/rejected, remove the debugging statements that supported that test - you know the answer to your prediction, so that code is no longer needed.
  • Keep a WRITTEN list of your predictions and what you now know about the program (later on you MIGHT be able to keep it all in your head, but that is unlikely when you have complex programs)
  • Make a SINGLE, testable change to the program in response to what you learn from your prediction.
  • Remember to make and WRITE down a prediction before running the program.
  • The key goal when running the program like this is to be surprised - you want to learn something that does not match your prediction.
  • Start your debugging process at the start of the program sequence - it is pointless to check the final outputs if you are not sure that the inputs are being read correctly.
  • Initially simplify the program inputs as much as possible, so ONE Quiz Result initially, make sure that case works, then add more as you validate that it seems to work for the previous inputs.

© 2016 Pete McBreen Seeing, contrary to popular wisdom, isn’t believing. It’s where belief stops, because it isn’t needed anymore. — Terry Pratchett (Pyramids)