3 ms·
Could someone explain this one? > Be Defensive [...] Defensively assert about the state of parameters passed in methods, constructors, and mid-method. If someo
by viraptor 17y ago
Could someone explain this one?
> Be Defensive [...] Defensively assert about the state of parameters passed in methods, constructors, and mid-method. If someone can pass in a null, you've left your guard down. You see, there are testing freaks out there that like to instantiate your object, or call a method under test and pass in nulls!
I'm not sure what he wants to change. Surely if the code would crash when I pass a null as an argument, it's better to make it throw the exception as early as possible. You can test that by asserting an exception when you call that_func(null);.
Why is that a bad thing? (Or did I misunderstand him?)
- req2 17y agoIn the comments he admits that public APIs should be defensive, but internal APIs should be 'known good' via testing.