|
|
|
Guidelines for
Writing Bullet-Proof Code
By Dan Clamage
When writing Production-quality software, take the attitude of making all your code bullet-proof
right up-front, the first time through coding (instead of thinking "I'll add it later"). This requires a tedious amount of pessimism about your own code. It seems like overkill while you're writing it, but it'll really save your butt.IF (local_var = 'YES') THEN
...
ELSIF (local_var = 'NO') THEN
...
ELSIF (local_var = 'MAYBE') THEN
...
ELSE -- should never happen!
...
END IF;The final test, which would be an unexpected error, handles the unexpected.
Without it, should the situation arise, you would never know, and the program would behave in an unanticipated manner. If anybody can think of any other trouble-shooting guidelines, or disagrees with mine, send them in! I could go on for days with horror stories related to "expedient" programming. Here's a quick one:A programmer dispensed with exception handlers for implicit queries
(SELECT INTO). So I made her put them in. Then I saw she had simply coded a NULL statement for each exception handler! So I made her write the SQLERRM for the SQLCODE value returned, to a log table. On the next run, we examined the log table and discovered she was getting a VALUE_ERROR on certain rows, so that the value from the previous row was still being used (the variable being Selected INTO is not written to on an error)! She fixed the bug and got very different results!************************************************************