<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Introduction to Code Contracts [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx</link><description>This blog post is to provide a bit more detail about the Code Contracts feature that was recently announced at the PDC and in Justin’s blog entry , and that can be found in the Visual Studio 2010 and .NET Framework 4.0 CTP . I’ll include some information</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Introduction to Code Contracts [Melitta Andersen] | Tmao Coders</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9060999</link><pubDate>Wed, 12 Nov 2008 03:02:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9060999</guid><dc:creator>Introduction to Code Contracts [Melitta Andersen] | Tmao Coders</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.tmao.info/introduction-to-code-contracts-melitta-andersen/"&gt;http://www.tmao.info/introduction-to-code-contracts-melitta-andersen/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Introduction to Code Contracts [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9061355</link><pubDate>Wed, 12 Nov 2008 07:57:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9061355</guid><dc:creator>snprbob86</dc:creator><description>&lt;p&gt;C# and Python are tied for my favorite languages. Attributes are cool, but Python's decorators are cooler.&lt;/p&gt;
&lt;p&gt;Check out these simple precondition and postcondition decorators:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://wiki.python.org/moin/PythonDecoratorLibrary#head-e1a9273f88f2fc4e39faf297279f4d1dc8b2ae66"&gt;http://wiki.python.org/moin/PythonDecoratorLibrary#head-e1a9273f88f2fc4e39faf297279f4d1dc8b2ae66&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>.NET 4.0's game-changing feature? Maybe contracts...</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9061707</link><pubDate>Wed, 12 Nov 2008 12:28:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9061707</guid><dc:creator>Jon Skeet: Coding Blog</dc:creator><description>&lt;p&gt;Update: As Chris Nahr pointed out, there&amp;amp;#39;s a blog post by Melitta Andersen of the BCL team explaining&lt;/p&gt;
</description></item><item><title>re: Introduction to Code Contracts [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9064129</link><pubDate>Wed, 12 Nov 2008 22:52:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9064129</guid><dc:creator>Jonathan Pryor</dc:creator><description>&lt;p&gt;If I make one API suggestion (which may already be followed, I have no idea)...&lt;/p&gt;
&lt;p&gt;Ensure&lt;/p&gt;
&lt;p&gt;You mention:&lt;/p&gt;
&lt;p&gt;&amp;quot;They also have an overload that takes a string parameter as a message for when the contract is false.&amp;quot;&lt;/p&gt;
&lt;p&gt;Please, *please*, PLEASE make the overloaded method take a &amp;quot;string format, params object[] args&amp;quot; argument list and not just a string. &amp;nbsp;For simple code there will be no difference for the developer, but if you ever need to &amp;quot;format&amp;quot; the message string it looks far cleaner than needing to insert string.Format(). &amp;nbsp;Compare:&lt;/p&gt;
&lt;p&gt;CodeContract.Requires(parameter &amp;gt;= 0, &amp;quot;parameter value {0} must be greater than 0&amp;quot;, parameter);&lt;/p&gt;
&lt;p&gt;To:&lt;/p&gt;
&lt;p&gt;CodeContract.Requires(parameter &amp;gt;= 0, string.Format(&amp;quot;parameter value {0} must be greater than 0&amp;quot;, parameter));&lt;/p&gt;
</description></item><item><title>.NET 4.0 Contracts</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9064531</link><pubDate>Thu, 13 Nov 2008 01:40:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9064531</guid><dc:creator>Andrew Stopford's Weblog</dc:creator><description>&lt;p&gt;First showed at the PDC as a part of this Pex session was support for contracts , if you have seen the&lt;/p&gt;
</description></item><item><title>re: Introduction to Code Contracts [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9067313</link><pubDate>Thu, 13 Nov 2008 23:19:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9067313</guid><dc:creator>Steven the .NET Junkie</dc:creator><description>&lt;p&gt;This is the greatest news I heard in years. I was very exited about the things Spec# could bring us, but bringing verification to the rest of the framework is superb. The most development teams I help use C# and moving to another language wouldn’t be feasible for them.&lt;/p&gt;
&lt;p&gt;I have a question though. I’m a big believer of the Framework Design Guidelines and they state that a failing precondition should throw an ArgumentException (or descendant). How does Contracts deal with this?&lt;/p&gt;
&lt;p&gt;I don’t think it’s necessarily to add a ‘string, parms object[]’ overload to the Requires and Ensures methods, as Melitta Andersen suggests. Using a string.Format() would be sufficient when the post-compilation process changes the implementation to something like ‘if (conditions) throw new Exception(string.Format(…))’. How is this currently implemented?&lt;/p&gt;
</description></item><item><title>re: Introduction to Code Contracts [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9076746</link><pubDate>Fri, 14 Nov 2008 22:45:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9076746</guid><dc:creator>Judah Himango</dc:creator><description>&lt;p&gt;First, great news! I think this is *the* best news coming out for .NET 4. It's something I've wanted for years.&lt;/p&gt;
&lt;p&gt;Question:&lt;/p&gt;
&lt;p&gt;Care to talk a little bit about how this works for interfaces, where you can't actually put code inside your methods? &lt;/p&gt;
&lt;p&gt;interface IFoo&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;DoSomething(string s)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CodeContract.Requires(s != null);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;};&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;In the above interface, the compiler will issue an error; you can't have code statements inside an interface.&lt;/p&gt;
&lt;p&gt;(This is another argument in favor of using attributes, as they are allowed in interfaces.)&lt;/p&gt;
&lt;p&gt;Another question:&lt;/p&gt;
&lt;p&gt;If attributes were powerful and expressive enough, would the team consider implementing code contracts using attributes? I ask because there has been a lot of feedback on the MS Connect website to allow more expressiveness inside attributes. See &lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=254057"&gt;https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=254057&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Introduction to Code Contracts [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9080919</link><pubDate>Sat, 15 Nov 2008 02:22:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9080919</guid><dc:creator>BCLTeam</dc:creator><description>&lt;p&gt;Hi snprbob86, &lt;/p&gt;
&lt;p&gt;Thanks for passing along the link to the Python decorators. &amp;nbsp;That looks like an interesting contract system, and seems to have some of the same concepts as the one we implemented. &amp;nbsp;For example, the ability to have contracts at debug time only or the ability to incorporate functions into conditions to make them more expressive are elements of our own code-based implementation.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Melitta&lt;/p&gt;
</description></item><item><title>re: Introduction to Code Contracts [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9080940</link><pubDate>Sat, 15 Nov 2008 02:24:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9080940</guid><dc:creator>BCLTeam</dc:creator><description>&lt;p&gt;Hi Jonathan,&lt;/p&gt;
&lt;p&gt;Thanks for the API suggestion. &amp;nbsp;It's an interesting idea, and does make the code a little neater. &amp;nbsp;However, at this point we're trying to keep the code contract APIs as minimal as possible. &amp;nbsp;This makes it less complicated for the tools to extract the conditions. &amp;nbsp;Overloads with more parameters make the task more difficult. &amp;nbsp;It's something we'll think about, but we may not be able to make it happen in this release.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Melitta&lt;/p&gt;
</description></item><item><title>re: Introduction to Code Contracts [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9080953</link><pubDate>Sat, 15 Nov 2008 02:26:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9080953</guid><dc:creator>BCLTeam</dc:creator><description>&lt;p&gt;Hi Steven,&lt;/p&gt;
&lt;p&gt;You have some good questions here. &amp;nbsp;We don't have any official Framework Design Guidelines yet for when to use code contracts and when to use ArgumentExceptions. &amp;nbsp;While many of us are fans of contracts, clearly we can't just say &amp;quot;change all of your existing preconditions to code contracts,&amp;quot; because there is often already infrastructure in place around throwing these ArgumentExceptions and there is too much potential to break people. &amp;nbsp;This is a brand new feature, and we're doing some experimentation internally to find out what works best so that we can make more informed recommendations.&lt;/p&gt;
&lt;p&gt;As for your question about how we implement the behavior of code contracts under the hood, we don't convert it to an exception. &amp;nbsp;In the CTP bits we check the condition and then tear down the process if they fail. &amp;nbsp;We use the string as part of a message to the user when this happens. &amp;nbsp;As I mentioned above, we're considering options to make this behavior more flexible, and especially to make it friendlier to hosts. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Melitta&lt;/p&gt;
</description></item><item><title>re: Introduction to Code Contracts [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9080968</link><pubDate>Sat, 15 Nov 2008 02:27:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9080968</guid><dc:creator>BCLTeam</dc:creator><description>&lt;p&gt;Hi Judah,&lt;/p&gt;
&lt;p&gt;Thanks for pointing out that I neglected to mention how code contracts work on interfaces. &amp;nbsp;As you've said, you can't put code into interface methods. &amp;nbsp;What you do is create a separate class to contain the contracts that &amp;lt;i&amp;gt;explicitly&amp;lt;/i&amp;gt; implements the interface. &amp;nbsp;Then you link them with a pair of attributes: &amp;nbsp;[ContractClass(Type)] and [ContractClassFor(Type)]. &amp;nbsp;For example you could have an interface IFoo &amp;nbsp;with a class IFooContract that contains the contracts.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[ContractClass(typeof(IFooContract))]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;interface IFoo&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int DoSomething(string parameter);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[ContractClassFor(typeof(IFoo))]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;sealed class IFooContract : IFoo&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int IFoo.DoSomething(string parameter)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CodeContract.Requires(parameter != null);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CodeContract.Ensures(0 &amp;lt;= CodeContract.Result&amp;lt;int&amp;gt;());&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;throw new NotImplementedException(&amp;quot;This method is only for interface contracts. &amp;nbsp;Do not call&amp;quot;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;As for your question about attributes, if they were powerful enough, we certainly would have considered using them to implement contracts, though I can't say for sure what we would have decided. &amp;nbsp; &amp;nbsp;As it is, we don't know of any plans for more expressive attributes, and even if they do come along later, we would already have an established contracts system. &amp;nbsp;There would by that point be many factors to take into consideration when looking at adding attribute support.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Melitta&lt;/p&gt;
</description></item><item><title>re: Introduction to Code Contracts [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9098000</link><pubDate>Sat, 15 Nov 2008 16:57:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9098000</guid><dc:creator>Steven the .NET Junkie</dc:creator><description>&lt;p&gt;I don't like using attributes for the contracts. It’s almost impossible to do compile time checking on them, and they’re very verbose. I've seen Spec# and it has the ideal language syntax. I hope this syntax makes it to C# 5.0. (Well… I'm really hoping C# 4.0 will have all this, but I know this isn't going to happen ;-)).&lt;/p&gt;
</description></item><item><title>re: Introduction to Code Contracts [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9102764</link><pubDate>Sun, 16 Nov 2008 12:24:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9102764</guid><dc:creator>int19h</dc:creator><description>&lt;p&gt;Judging by its past track, one .NET language that will almost certainly provide syntactic sugar for the library contracts is Delphi Prism (aka RemObjects Oxygene). They do in fact already have &amp;quot;require&amp;quot;, &amp;quot;ensure&amp;quot;, and &amp;quot;invariant&amp;quot; keywords, so it would make sense for them to plug them into those BCL bits for .NET 4.0, and extend the syntax to cover all other cases (&amp;quot;require ... on raise ...&amp;quot; etc).&lt;/p&gt;
</description></item><item><title>Various Links</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9130259</link><pubDate>Thu, 20 Nov 2008 23:02:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9130259</guid><dc:creator>Mike Taulty's Blog</dc:creator><description>&lt;p&gt;I've been catching up on my blog reading...interesting stuff I came across; PNRP in Windows 7 being...&lt;/p&gt;
</description></item><item><title>契約によるプログラミング.NET</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9142081</link><pubDate>Tue, 25 Nov 2008 18:08:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9142081</guid><dc:creator>biac の それさえもおそらくは幸せな日々@nifty</dc:creator><description>&lt;p&gt;InfoQ に日本語記事が載ったので f(^^; .NET 4 の新機能を探る： コード契約作者 Jonathan Allen, 翻訳者 金森 諭 投稿日 2008年11月22日 午前12時53分 契約による設計は静的型付けのように、 コンパイル時に検証されないと一定の動作を実行することができないという考え方だ。 契約&lt;/p&gt;
</description></item><item><title>re: Introduction to Code Contracts [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9160748</link><pubDate>Mon, 01 Dec 2008 19:11:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9160748</guid><dc:creator>Flavien Charlon</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Contracts are really nice.&lt;/p&gt;
&lt;p&gt;In order to be able to use them properly though, we will need pre and postconditions from all the classes we use in our program, for exemple, List&amp;lt;T&amp;gt;.Count is always positive or zero.&lt;/p&gt;
&lt;p&gt;Are you going to update the whole BCL with code contracts for .NET 4.0? This sounds like a huge work, but without that, contracts won't be usable at their full potential.&lt;/p&gt;
&lt;p&gt;My second question is why C# wouldn't have a syntax that would get translated into CodeContracts upon compilation.&lt;/p&gt;
&lt;p&gt;With this we get a good langage support in C#, as well as the ability to have it supported accross all CLR langages.&lt;/p&gt;
</description></item><item><title>Preview of Code Contract Tools Now Available [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9441885</link><pubDate>Tue, 24 Feb 2009 02:02:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9441885</guid><dc:creator>BCL Team Blog</dc:creator><description>&lt;p&gt;In my Introduction to Code Contracts post, I mentioned that the tools to enable runtime checking and&lt;/p&gt;
</description></item><item><title>Preview of Code Contract Tools Now Available</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9458864</link><pubDate>Wed, 04 Mar 2009 23:06:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9458864</guid><dc:creator>CLR Team Blog</dc:creator><description>&lt;p&gt;We’ve mentioned Code Contracts over on the BCL Blog a few times now, but never yet on the CLR Blog. Basically,&lt;/p&gt;
</description></item><item><title>Relacja z C2C (Communities to Communities) 2009</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9480011</link><pubDate>Mon, 16 Mar 2009 01:59:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9480011</guid><dc:creator>. jak .NET by Maciej Aniserowicz</dc:creator><description>&lt;p&gt;Dzień: 14 marca 2009. Miejsce: Wydział Biologii UW. Wydarzenie: druga edycja konferencji Communities&lt;/p&gt;
</description></item><item><title>Relacja z C2C (Communities to Communities) 2009</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx#9480014</link><pubDate>Mon, 16 Mar 2009 02:00:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9480014</guid><dc:creator>. jak .NET by Maciej Aniserowicz</dc:creator><description>&lt;p&gt;Relacja z C2C (Communities to Communities) 2009&lt;/p&gt;
</description></item></channel></rss>