When is your code too defensive?


I had a discussion with some fellow developers a little while ago about DesignByContract and creating defensive code. The subject of being *too* defensive came up in the fact that while writing defensive code is a good thing, it’s not hard to go off the deep end and start building too many walls protecting your fort.

Any good developer has a certain level of skepticism when writing a line of code that depends on something from a related class/system. This includes checking for errors, making sure things are in an expected state, QA testing etc…, but when does this become too much of a burden?

Refactoring to Tests