Ran across this paper the other day - 7 'secrets' of successful programming. I liked it - sort of fit in with my debugger rant from yesterday - especially point number four which I'm going to copy and quote here:
4. Expect the unexpected and deal with it
Before you open a file, make sure that the file is present. Before you set focus to a control, make sure that the control is visible and enabled. Try to work out what conditions could cause your code to fail and test for them before they cause the program to fall over.
Expect the unexpected - deal with it. Words of wisdom and ties in nicely with "instrumentation". If you get something totally unexpected in your code - but have no way to record that fact, to transmit that bit of data back to you (or to the DBA or the team that maintains the code or the helpdesk or ...) you lose. Part of instrumenting is recording the unexpected - that is sometimes the best you can do to "deal with it". Your program very likely might have to "fall over" (gracefully! not with a segmentation fault or a "dr. watson") still - but you'll have recorded, or at least have the ability to record, why. Sort of like an Oracle trace file written during an ORA-00600. It would be better than just popping up some error dialog for the end user (see some classic examples here)
I'm putting together a couple of "do not try this at home" talks for upcoming events (sort of worst practices if you will). Hence you might see me talking more about what not to do than usual. Sort of like the "when others then null;" ranting I did not too long ago :)