I Love TDD and Code Contracts

After spending a few days writing a ton of code and heavily refactoring using TDD and Code Contracts I have to say… Wow!

I know people like to debate the value of TDD, test first etc.  I don’t care what they say – this method rocks.  I found bugs I would have never found any other way (including some product bugs).

Then when you add Code Contracts – double Wow!

At first I thought the Code Contracts might be too much.  They forced me to carefully consider what the behavior of my contracts are.  The more I used them the more I realized that I often was inconsistent in validating parameters or specifying a behavior.

For example, suppose I have a method that accepts a string parameter.

What if it is null?

What if it is string.Empty?

What if it is whitespace i.e. “    “

Specifying the contract on the interface forces me to specify the behavior that I expect all classes that implement the interface to implement.  In a scenario where many different people are going to implement the interface this is invaluable.

Sure it is a little more code.. ok a lot more code.  BUT IT IS CODE THAT WORKS AND I CAN PROVE IT!!!

That is what I really love…

Comments (0)