Debugging a computer program:

  1. Design well from the beginning.

2. When you start coding, write a small amount of code, compile it, correct any syntax errors, recompile it, continue until the syntax errors are corrected. Then add another small amount of code (approximately 8 to 10 lines), compile it, etc.

Continue entering code in this fashion until all of the code is entered. In cases where you are entering looping structures, you may want to just get the loop working first (printing the loop variable to check for correct operation). Once the loop is working you can go about including other operations to be performed within the loop.

3. Test modules separately, using driver programs.

4. Test main module separately, using stubs for modules when necessary.

static boolean isDivisor(int dividend, int possibleDivisor)

{

return true; // return dummy value

}

5. Use output to show where your program is in execution (if necessary)

6. Use the compilers error messages to determine approximately where a syntax error is located, then closely examine the offending code, looking for the error.

  1. Hand execute the code, tracing the values of variables with the progression of the program.
  1. Get a programming partner who can scan your program, looking for errors in logic or syntax (and you, of course, will do the same for your partner when necessary).
  2. Start early, and remember that "short cuts" can often extend the time spent programming by a considerable amount.