News for hackers. Stuff that matters.
Re:How to write untestable code by viraptor on Thursday November 05, 2009 @05:50PM (#924969)
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?)

Re:How to write untestable code by req2 on Thursday November 05, 2009 @06:10PM (#925009)
In the comments he admits that public APIs should be defensive, but internal APIs should be 'known good' via testing.