Scholarly Resources for CompSci Undergrads

Debugging Advice

Here is some of the advice about detecting and avoiding mistakes programmers often make in C and other languages.

Table of Contents

Common Errors

M. R. Murphy wrote:

About ten years ago I started keeping a list of the errors that I made in programs. I made the list in the form of questions to ask myself as I stared blankly at a {dump|hung machine|garbage output}. I tacked the list on the wall next to my desk and added a new question each time I found that I had made YASM (stupid mistake).

After a while, the additions to the list became less frequent, not because I made fewer SM's, but because each mistake could be classed as one already on the list.

Here's the list. I'm curious, can you add to it?

  1. Is the argument count correct?
  2. Is the spelling correct?
  3. Is the argment type correct?
  4. Is the variable initialized correctly?
  5. Do "ends" match "do"s?
  6. Is the correct register used?
  7. Is a previous equate, using, or define in effect?
  8. Is the level of indirectness correct?
  9. Are the defaults correct?
  10. Is the array large enough to hold the data?
  11. Is the index out of range?
  12. Is reentrancy, reusability, refreshability preserved?
  13. Did you let something go by that you can't explain? Fix it now.
  14. Does the program have anything remotely to do with the requirement for the program?
  15. Did you start to code before thinking?
  16. Did you read the manual?

See Also

The April 1997 edition (vol. 40, no. 4) of Communications of the ACM contained several articles about `the debugging scandal'. My Hairiest Bug War Stories by Marc Eisenstadt on pages 30 to 37 is most similar to M. R. Murphy's list.

Brace Styles in C

Ron House had this to say about brace styles in C:

vjpachiano@ccgate.dp.beckman.com (Vincent J. Pachiano Jr.) writes:
<My all time favorite !!!

<for (i = 0; i < 99; i++);
<{
<   some_reptitious_code_1;
<   some_reptitious_code_2;
<}


<Now scratch your head and ask why the loop doesn't
<execute 99 times!! Stupid error (Yes), but one of my
<top 10 favorites!!

So stop using an objectively defective program layout style! Write it as:

for (i = 0; i < 99; i++) {
   some_reptitious_code_1;
   some_reptitious_code_2;
}


and the error is psychologically virtually impossible.

See also

I've made copies of my lecture notes about debugging from the ~jamie/CS201 directory on the GAUL computers at UWO available here. Undergraduates at UWO can find more tips (and another copy of those debugging notes) in that directory. If you are not at UWO, do not despair you are missing a small amount of very specific debugging advice. The rest has nothing to do with debugging.

Everyone can find more at the UofT archive and in my list of recommended books.

This document is intended primarily for undergraduate students in computer science at the University of Western Ontario. It is part of my list of undergrad resources and an experiment with different ways of presenting information.


J. Blustein
<jamie@csd.uwo.ca>
http://www.csd.uwo.ca/~jamie/.Refs/misc_debug.html

HTML 2.0 Checked!