Defensive and offensive programming

For a soccer forward player, 1 success out of 100 attacks may mean a successful match.

But for a defender, only one failure may be all it takes to lose a match.

Many programming tasks are defensive by nature. Errors are best avoided by certain defensive practices like configuration management, automated tests, encapsulation, static analysis like type checking, idioms and other coding standards that strive for readability etc.

On the other hand, it's good to recognize the offensive tasks, too, in which the number of failures doesn't matter as long as there are some successes, too. It doesn't matter how many bad languages, frameworks, patterns or designs you try if it helps you to find the ones that work.

Often it's impossible to score without taking the risk of losing the ball.

Originally published on 2008-06-27 at under category Art of programming