Chapter 1. ON THE DEFENSIVE

Defensive Programming Techniques for Robust Code

We have to distrust each other. It’s our only defense against betrayal.

Tennessee Williams

When my daughter was 10 months old, she liked playing with wooden bricks. Well, she liked playing with wooden bricks and me. I’d build a tower as high as I could, and then with a gentle nudge of the bottom brick, she’d topple the whole thing and let out a little whoop of delight. I didn’t build these towers for their strength—it would have been pointless if I did. If I had really wanted a sturdy tower, then I’d have built it in a very different way. I’d have shorn up a foundation and started with a wide base, rather than just quickly stacking blocks upon each other and building as ...

Get Code Craft now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.