Here is some of the advice about detecting and avoiding mistakes programmers often make in C and other languages.
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?
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.
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.
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.