Simple debugging

Stop / start testing

Development environments offer a variety of complex debugging tools to use when the program does not do what you expect. A simple alternative, particularly for small programs, is to use comments, print statements and an early exit from the program to test the logic. If a problematic function is meant to return or modify some data, interrupt the code to print the output of the function and, optionally, quit the program to prevent bad data from causing further errors later in the program. This allows you to see exactly what the function is returning with real data as well as allowing you to make changes and see the effects. The program will need to be re-compiled for each test but by commenting out lines that have already been tested, you can isolate the function and the auxillary code that provides data to the function. As a further aid, consider only running the code with fixed input - instead of providing real data, comment out the auxillary code and set the variables manually before the function you want to test and print the changes afterwards.

This is part of Copyright © 1998-2004 Neil Williams
See the file about.html for copying conditions.