May 18, 2010

I was out of the office for 2 weeks. When I returned, I was pairing with two of my coworkers. They each reported cases in which code contracts alerted them to accidental misuse of code. They probably would have found their problem eventually. But the presence of code contracts, combined with a rich set of automated tests, detected the problems sooner than they might have otherwise. This was more positive reinforcement for me that code contracts are a valuable technique to include in a system’s design. They help steer you or your coworkers away from incorrect usage.

Don’t forget to add the optional descriptive text parameter to your contracts. What is a “good” contract comment? Imagine you are another programmer, and you accidentally violate a contract. Is the reason for the contract’s existence obvious to you? If not, then you should explain WHY the contract has been placed there.