Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Defensive Programming

Name: Anonymous 2008-09-13 18:26

I used to be a student of the ``Defensive Programming'' school of programming. I'm mainly a C programmer, but I occasionally dabble in languages such as LISP. Anyways, whenever I would program in C, I would program very defensively, and check that all the arguments passed to every function were not NULL (assuming they were pointers. This turned my code into mostly a bunch of if statements.

After a while, I figured out that this was pointless, and most of the functions I write today, I don't bother checking if the arguments are NULL or not, because only a smart fucker such as myself is going to be using them. I instinctively know when everything is NULL or not. Of course, I do still check the arguments sometimes, but definitely not in every function. It just turns into a mess.

What do you guys do? Am I a retard, or are you similar?

Name: Anonymous 2008-09-13 21:01

When you must fail, fail noisily and as soon as possible.

I prefer a segfault than a silent fail, because the latter leads to lots of tracing and "now where did that pointer get set to null? It's going to be pretty hard to tell if the fuckton of functions called since have just been returning and letting things continue..."

I've also seen stuff like this:

a=1;
... /* a bunch of code which doesn't do anything at all with a */
if(a!=1) {
 /* some sort of error-recovery shit */
}
...


I don't think you should be checking the hardware to see if it's doing things right (unless it's a diagnostic program of some sort), because if the hardware is dying then all bets are off for the software.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List