PRACTICAL PROGRAMMING ADVICE

2 Defensive Coding Techniques You Should Use Today

Simple but powerful techniques for safe, maintainable software

Nicklas Millard
The Startup
Published in
3 min readJul 3, 2020

--

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…

--

--

Nicklas Millard
The Startup

I mostly write to "future me" sharing what I learn and my opinion on software development practices. youtube.com/@nmillard | open for contracts in Jan 2026.