A couple of weeks ago I saw Jon Skeet (all hail the Skeet) present on code contracts in Visual Studio. Code Contracts grew out of Spec#, which took inspiration from Eiffel and are a useful way of baking in constraints and requirements for method arguments. Code contracts are available from Microsoft Research for VS2008 and is being baked into .NET 4.0 and VS2010. It’s useful stuff for ensuring code quality (MS used the Spec# bits in the System.Cryptography namespace in .NET 3.0) – however there’s a problem.
When MS took the leap to providing a unit test system they dropped the ball. In fact they threw the ball off the field – they didn’t make unit testing available to the cheaper SKUs of Visual Studio, and they’re doing the same with Code Contracts. In VS2010 the static checking of code contracts will be limited to the Team System SKUs (which wasn’t the case with Spec#) – that’s the horribly expensive ones. If you have a cheaper version of Visual Studio then only runtime checks will be performed so you won’t know about a failure until you, or one of your users encounters it. It seems the lessons that should have been learnt with MSTest weren’t.
Code contracts without static checking becomes just another way of argument checks, and a way where you can’t catch exceptions and react accordingly. So go vote on connect to make static checks available to the lower SKUs, make your voice heard and let’s see if we can’t get DevDiv to do the right thing.