In a Nutshell
Draw water for the siege, strengthen your defenses! Work the clay, tread the mortar, repair the brickwork!
It is important to craft code that is not just correct but is also good. It needs to document all the assumptions made. This will make it easier to maintain, and it will harbor fewer bugs. Defensive programming is a method of expecting the worst and being prepared for it. It’s a technique that prevents simple faults from becoming elusive bugs.
The use of codified constraints alongside defensive code will make your software far more robust. Like many other good coding practices (unit testing, for example—see "The Types of Test" on page 138), defensive programming is about spending a little extra time wisely (and early) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access