PRACTICAL PROGRAMMING ADVICE
2 Defensive Coding Techniques You Should Use Today
Simple but powerful techniques for safe, maintainable software
I’ll keep this one short and sweet.
We’ll be going over two very simple and practical defensive techniques you can start applying to your project today.
As a professional developer, chances are you’re already applying these techniques, so you might want to sit this one out.
However, for anyone who’s yet to reach a professional level, these techniques will improve your quality and make your code safer.
If you’ve never heard of defensive coding before, it’s about time. Here’s the gist of it.
Defensive coding allows our software to behave in a correct manner, despite incorrect input.
Right, let’s look into how you can make your software behave nicely, even when it’s provided with wrong inputs.
Guard Clauses — checking preconditions
These one-liners are one of the absolute cornerstones of defensive coding. They sit at the top of your methods making sure the methods only continue executing when valid…