Software Quality

May 18, 2010

Code Contracts really speed development

Filed under: Code Contracts, Uncategorized — David Allen @ 8:45 pm

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.


void Deposit(decimal amount){
   Contract.Requires(amount  > 0,"system does not accept zero or negative deposits");

Code contracts are just one technique for your toolbox. But they are a useful tool to include in your systems. So don’t forget to develop your skill at contract programming.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: