 <p>I'm not a fan of the term "defensive programming". To me it suggests code like this:</p> <pre><code>void MakePayment( Account * a, const Payment * p ) { if ( a == 0 || p == 0 ) { return; } // payment logic here } </code></pre> <p>This is wrong, wrong, wrong, but I must have seen it hundreds of times. The function should never have been called with null pointers in the first place, and it is utterly wrong to quietly accept them. </p> <p>The correct approach here is debatable, but a minimal solution is to fail noisily, either by using an assert or by throwing an exception.</p> <p><strong>Edit:</strong> I disagree with some other answers and comments here - I do not think that all functions should check their parameters (for many functions this is simply impossible). Instead, I believe that all functions should document the values that are acceptable and state that other values will result in undefined behaviour. This is the approach taken by the most succesful and widely used libraries ever written - the C and C++ standard libraries.</p> <p>And now let the downvotes begin...</p>