VISUG: Code contracts in .Net 4.0

From the archive: written in 2009 and kept for the record. Much of it is out of date.

Yesterday I went to my first VISUG event. VISUG stands for Visual Studio User Group and is the independent professional user group for Microsoft Visual Studio users in Belgium. The presentation, titled “C# 4.0 and testability”, and given by Dino Esposito, addressed the importance of testability in applications, and how this is made easier with code contracts.

Code Contracts provide a language-agnostic way to express coding assumptions in .NET programs. The contracts take the form of preconditions, postconditions, and object invariants. They act as checked documentation of your external and internal APIs. The contracts are used to improve testing via runtime checking, enable static contract verification (yay!), and documentation generation. In short, they bring the advantages of design-by-contract programming to all .NET programming languages.

Jeroen De Dauw is founder and CEO of Professional Wiki and builds NeoWiki. More about me. Reply by email or on Mastodon, Bluesky or X.