Enhance Your Code Quality with Code Contracts

Abstract

If you ever used a 3rd party API, you surely know the importance of proper documentation – Can this method return “null”? Do I have to check this return value? What are the valid values of this argument? You also probably know that the only way to discover if your assumptions are correct is to execute the code and pray that exceptions won’t be flying around. There must be a better way!

Enter “Code Contracts”. Code Contracts is an experimental project from Microsoft Research which provides a language-agnostic way to express coding assumptions in .NET programs, thus allowing for improved testability, static verification at compile time and automatic API documentation.

In this session we’ll take a tour around Code Contracts, understand when and how we can use them, and show how correct usage of these constructs can significantly increase the quality of your code.

Slide Deck