title: Code Contracts in .NET 4.0, no joy for non-nullable reference types fans?
body: <p>I've been playing with Code Contracts on VS2008 (<a href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx</a>).<br>
  They surely are nice and provide a solid alternative to if-then-throw checks inside methods.</p>
  
  <p>Nonetheless I've been hoping that they could satisfy the need that I strongly feel for non-nullable reference types.<br>
  Alas, from what I could see this doesn't seem to be the case.<br>
  This is what I understood:</p>
  
  <ul>
  <li><p>Something like this will still cause issues at runtime:<br>
  <code>
  MyClass a = null;<br>
  a.ToString();
  </code>  </p></li>
  <li><p>I still have to explicitly write checks, even if in a more concise and streamlined way.</p></li>
  <li><p>Unless you use VS Team System you can only use code contracts to check things at runtime, no benefits at compile time.<br>
  Meaning that you still have to handle things when something goes wrong.<br>
  Not much different from handling a simple exception.</p></li>
  <li><p>Even with VSTS static analysis isn't as a good as the one done at runtime.<br>
  This is perfectly understandable, still it's another sign that this feature is meant for runtime usage.</p></li>
  </ul>
  
  <p>Please correct me if I'm wrong but from what I see there's no way Code Contracts can make my life easier, and my programs more robust, like non-nullable reference types would.  </p>
  
  <p>Don't get me wrong, I don't dislike code contracts.<br>
  They are a very nice enhancement to the whole framework.<br>
  It's just that if this doesn't fill the gap that C# leaves by not having non-nullable reference types, at this point I'm afraid that nothing will.<br>
  What do you think?</p>