<?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>Progressive Development : design by contract</title><link>http://blogs.msdn.com/progressive_development/archive/tags/design+by+contract/default.aspx</link><description>Tags: design by contract</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Motley says: "Contracts do me no good at run-time"</title><link>http://blogs.msdn.com/progressive_development/archive/2007/05/15/motley-says-contracts-do-me-no-good-at-run-time.aspx</link><pubDate>Wed, 16 May 2007 07:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2664423</guid><dc:creator>James Waletzky</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/progressive_development/comments/2664423.aspx</comments><wfw:commentRss>http://blogs.msdn.com/progressive_development/commentrss.aspx?PostID=2664423</wfw:commentRss><description>&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri; TEXT-DECORATION: underline"&gt;Summary&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;Motley: &lt;/SPAN&gt;I am not going to take time to specify my API contracts if there are no tools to help validate them&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;Maven: &lt;/SPAN&gt;Languages like Spec# and Eiffel have Design By Contract semantics built-in and can greatly improve the reliability of your software&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;[Context:&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;A continuing conversation between Maven and Motley about contracts - this time about tools]&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: I can see how thinking about interface contracts - including preconditions, postconditions, and class invariants - can help drive unit test creation. But, I am definitely not going through the effort of writing all this stuff down. I'll just use it to help my thinking.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Well, it definitely helps thinking, but there can be reasons to formally specify - write down - the contract around your APIs. &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: For what benefit?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Some languages, like &lt;A href="http://www.eiffel.com/"&gt;Eiffel&lt;/A&gt;, have had what are called "design by contract" constructs for years to help developers build higher quality software. These constructs are also making their way into more modern languages like C#, which you use every day.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: I don't remember seeing like this in the C# language. Are you high on something?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Actually, Microsoft is doing a bunch of work here, but it is still mostly research at this point. The technology is called Spec#, and it adds Design By Contract constructs as an addition to the C# language. &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Ahhhh… research = vaporware.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Well, not quite Mr. Pessimist. There actually IS a Visual Studio add-in that you can play with today. I'll give you the link later.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: I noticed you used the word "play" above. Not ready for prime time?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: You are very good at reading into things. That's right - I would not use it in production code at the moment, but if I was a betting man, I would think that Microsoft will include the constructs in the language in the future.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Ok, I am curious enough - how does it work?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Assuming you understand preconditions, postconditions, and class invariants as we discussed previously, you already understand the concepts behind Spec#. The native Spec# implementation makes some enhancements to the C# compiler such that it understands some new keywords. I'll talk about the ones most related to design by contract and &lt;SPAN style="FONT-WEIGHT: bold"&gt;bold&lt;/SPAN&gt; them below. Here is an example:&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in; FONT-FAMILY: 'Lucida Console'"&gt;public class Employee&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in; FONT-FAMILY: 'Lucida Console'"&gt;{&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: 'Lucida Console'"&gt;private string employeeName;&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: 'Lucida Console'" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: 'Lucida Console'"&gt;public void CreateEmployee(string name)&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.75in; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;requires&lt;/SPAN&gt; name != null &amp;amp;&amp;amp; name.Length &amp;gt; 0 &lt;SPAN style="FONT-WEIGHT: bold"&gt;otherwise&lt;/SPAN&gt; ArgumentException;&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: 'Lucida Console'"&gt;{&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.75in; FONT-FAMILY: 'Lucida Console'"&gt;this.employeeName = name;&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: 'Lucida Console'"&gt;}&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: 'Lucida Console'" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: 'Lucida Console'"&gt;public string ToString()&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.75in; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;invariant&lt;/SPAN&gt; employeeName ! = null;&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.75in; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;ensures &lt;/SPAN&gt;value.Length &amp;gt; 0;&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: 'Lucida Console'"&gt;{&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.75in; FONT-FAMILY: 'Lucida Console'"&gt;return "Employee: " + this.employeeName;&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: 'Lucida Console'"&gt;}&lt;/P&gt;
&lt;P style="FONT-SIZE: 9pt; MARGIN: 0in; FONT-FAMILY: 'Lucida Console'"&gt;}&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: The code above uses the following keywords that are added to C# by Spec#:&lt;/P&gt;
&lt;UL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.375in; DIRECTION: ltr; unicode-bidi: embed" type=circle&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;requires: &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;specifies a precondition; the name input parameter must not be null and must not be blank. If this condition is violated, an ArgumentException is thrown automatically.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;invariant: &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;When this routine executes the conditions must be true before and after; employeeName must be non-null.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;ensures: &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;specifies a postcondition; the return value of the method must contain a non-empty string&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: So how exactly is the contract checked? I would hope I am not doing all this work just to validate by hand.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Definitely not. The compiler inserts some inline prolog and epilog code into the compiled binary to check the conditions and throw exceptions to the caller if they are not satisfied. There is also a code analysis tool called "Boogie" that will check all of your code statically to make sure that all callers abide by the contracts.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Sounds interesting, but until it's ready for production code, I am not buying stock. &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: The important part is to understand the concepts and realize that design by contract is going to be more important moving forward. Plus, as we talked about previously, you can still use the concept to drive your unit tests. For now, C# still contains exception handling that you can use to validate things like preconditions, and debug assertions to validate invariants - definitely better than nothing. There's also a lot more that Spec# can do, but we'll save that for another time if you're interested.&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Pointer:&lt;/SPAN&gt; Design By Contract (DBC) has been around for a while, but is an underused technique to develop very reliable software. The developer mentality changes a bit when developing an API with a contract - you typically first think about and specify the contract before any implementation whatsoever. Then, regardless of what the implementation is, the contract typically stays the same.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Resources:&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://research.microsoft.com/specsharp/"&gt;Spec# from Microsoft Research&lt;/A&gt;, &lt;A href="http://research.microsoft.com/specsharp/papers/krml136.pdf"&gt;The Spec# Programming System: An Overview&lt;/A&gt;, &lt;A href="http://channel9.msdn.com/wiki/default.aspx/SpecSharp.HomePage"&gt;Spec# Wiki&lt;/A&gt;, &lt;A href="http://www.eiffel.com/developers/presentations/dbc/partone/player.html?slide="&gt;Design By Contract Overview in Eiffel&lt;/A&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2664423" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/progressive_development/archive/tags/design+by+contract/default.aspx">design by contract</category></item><item><title>Motley says: "Contracts are for baseball players and cell phones"</title><link>http://blogs.msdn.com/progressive_development/archive/2007/05/08/motley-says-contracts-are-for-baseball-players-and-cell-phones.aspx</link><pubDate>Tue, 08 May 2007 19:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2475132</guid><dc:creator>James Waletzky</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/progressive_development/comments/2475132.aspx</comments><wfw:commentRss>http://blogs.msdn.com/progressive_development/commentrss.aspx?PostID=2475132</wfw:commentRss><description>&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri; TEXT-DECORATION: underline"&gt;Summary&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;Motley: &lt;/SPAN&gt;Contracts don't apply to software - leave them for baseball players and cell phone providers&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;Maven: &lt;/SPAN&gt;Contracts (preconditions, postconditions, invariants) help drive your unit tests&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;[Context:&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Motley is all excited as he has started to measure code coverage on his tests]&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Hey Mot. Remember that conversation a while back that you said you were looking forward to as much as a cat looks forward to being neutered? I was looking over some of your unit tests and I think it's time we had it.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Yippee-ki-yay. You may know what the next part of that phrase is if you are a movie buff.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Ouch! I assume you're joking &amp;lt;laugh&amp;gt;. Anyway, about those tests. Your code coverage numbers are pretty good.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Excellent! Glad to hear something positive come out of your mouth!&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Absolutely. I think you are making some great progress and the other devs are really looking up to you as a leader. I do, however, have an idea to make your tests better. Bear with me for a second. Although the coverage numbers are good, you're still missing some cases as per our last conversation. &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Ok, you buttered me up a bit, so I assume you want something. I'll hear you out.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: A good way to ensure you thoroughly test a method is to think about the &lt;SPAN style="FONT-STYLE: italic"&gt;contract&lt;/SPAN&gt; of a method. &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Contracts are for baseball players and cell phone customers and providers. I don't see how this is relevant.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: If you think about your cell phone contract, your cell provider has certain expectations of you, and you have certain expectations of them. In the meantime, they may do some things that violate those expectations but they keep it invisible so that your expectations remain consistent. The same thing works for software. When you write a method, think about the preconditions of the method - what must be true before the method is called, the postconditions of the method - what must be true when the method is complete, and class invariants - what must be true before and after a method, but not necessarily during the execution of the method.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: I think better with examples, dude.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Sure. An example of a precondition might be that an integer input parameter must fall within a certain range. An example of a postcondition is that the returned object cannot be null. An example of a class invariant is that the state of the class must be some value before and after the method, but could change during the method, like before a call to a private method, and restored after that call.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Wow. That would be a lot of extra work to think about that for every method!&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: It &lt;SPAN style="FONT-STYLE: italic"&gt;is&lt;/SPAN&gt; extra work, but think about the benefits you gain when writing tests against a public method. Contracts help you frame your tests and make sure you have all boundary conditions/corner cases covered. Contracts also enhance the documentation around a method making it easier for someone to understand its usage.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: I can see some value in thinking this way, but going through all this extra work in specifying a contract just to think through my tests seems like lots of work for minimal gain.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Well, you'd have to thoroughly test the method anyway. This is just a different way to think about it. Let's cover how tools can actually help us out with validating contracts …&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Pointer:&lt;/SPAN&gt; Using contracts to design software is often referred to as Design by Contract. Thinking about your methods in terms of contracts helps drive quality of those methods. These contracts and associated unit tests actually become the formal specification of your software. Anyone wanting to know how the software is to be used (like the test team) can examine a contract and even without full documentation, can get an accurate picture of how the method is to be used.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Resources:&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://en.wikipedia.org/wiki/Design_by_contract"&gt;Design by Contract on Wikipedia&lt;/A&gt;, &lt;A href="http://www.artima.com/intv/contracts.html"&gt;An interview with Bertrand Meyer&lt;/A&gt;, who is credited with inventing the technique&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2475132" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/progressive_development/archive/tags/unit+testing/default.aspx">unit testing</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/design+by+contract/default.aspx">design by contract</category></item></channel></rss>