We're not talking about "clean code", We're talking about something more...
Defend against the impossible, because the impossible will happen
There are many definitions for Defensive Programming, but from my point of view, all the thing you need to know is:
- Never trust the input (user input, function parameters, ...). Do whitelists not blacklists, don't check for the invalid types but check for the valid types, excluding all the rest.
- Don't reinvent the wheel, use something that's already out there, well tested, trusted by thousands of developers and stable. The only reasons why you should build something by yourself is that you need something that doesn't exists or that exists but doesn't fit within your needs.
- Shouldn't trust other developer's code.
- Write SOLID code