
Defensive Coding Techniques You Should Use Today - kiyanwang
https://medium.com/swlh/2-defensive-coding-techniques-you-should-use-today-4225cacc1c29
======
necovek
TL/DR: When you start applying suggestions from this article, you are already
on the wrong path.

What, you've got too many arguments so you wrap it in an object
(AuthorSpecification)?

You're not even sure what input your method/function might get?

If it is an internal one, learn (I know that laziness is a virtue in a
developer, but you'll carry revalidating the same data in every function if
you do not). Oh look, I need to pass AuthorSpecification (already validated)
into this other method, which will revalidate it as part of the defensive
programming paradigm.

If it is an external facing one, sure, do some validation and publicize error
conditions.

Asserts are also a lazy way to raise custom exceptions: nothing wrong with
them, it's just that if your code will naturally fail (eg divide by zero),
there is no need to hide that exception with an assert beforehand.

But the author does not even use actual assertions, he demonstrates with a
trivial if, so I am not sure of the point.

