defensive programming

27th November 2021

What Does “Defensive Programming” Mean?

Defensive programming, simply put, is programming with the intent to anticipate likely failure points. The goal is to circumvent those likely problems before they occur. You see the problem, right? There’s something inherently difficult with the advice “expect the unexpected” and it’s made many times worse when one alters it to “expect the unexpected and try to prevent it”. Let’s look at some practical examples. Conditional Statements This is one of the easiest places to program defensively, and one where it’s easiest to be complacent. In many cases, while programming in PHP, you simply won’t need an “else” case. Hypothetically, […]