<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Spec#</title>
        <link>http://geekswithblogs.net/Podwysocki/category/7461.aspx</link>
        <description>Spec#</description>
        <language>en-US</language>
        <copyright>Matthew Podwysocki</copyright>
        <managingEditor>matthew.podwysocki@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>ALT.NET Open Spaces, Seattle Day 2 Recap</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/04/22/121513.aspx</link>
            <description>In my previous installment of recapping the events from ALT.NET Open Spaces, Seattle, I covered pretty much the opening ceremonies as it were.  The weather was definitely interesting the entire weekend.  Who would believe that we had snow, hail and rain for most of the time we were there in the latter half of April?  Mind you it didn't stick, but if you believe in God, there is something to be said of ALT.NET coming to town.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Coverage Galore&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://codebetter.com/blogs/jeffrey.palermo/default.aspx"&gt;Jeffrey Palermo&lt;/a&gt; was gracious enough to capture the opening ceremonies on video for all to see.  Here are some of the videos and they are well worth watching.  Really gives you an idea of how to run a good Open Spaces.  Doc did a wonderful job as a facilitator for the event.  And yes, that's me in the black coat in the background setting up for the event.&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://youtube.com/watch?v=kjzzQwOKMNA"&gt;ALT.NET Open Spaces, Seattle - Part 1&lt;/a&gt;&lt;br /&gt;
    An introduction by Doc on the meaning of Open Spaces&lt;br /&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://youtube.com/watch?v=kjzzQwOKMNA"&gt;ALT.NET Open Spaces, Seattle - Part 2&lt;/a&gt;&lt;br /&gt;
    More introduction and the suggestion of topics.  Everyone who submitted topics had to get in the middle of the room and declare their topic of interest.&lt;br /&gt;
    &lt;a href="http://youtube.com/watch?v=YuCGaBxjJhI&amp;amp;feature=related"&gt;&lt;br /&gt;
    &lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="javascript:void(0);/*1208901273499*/"&gt;ALT.NET Attendees - Why Did You Come to ALT.NET?&lt;/a&gt;&lt;br /&gt;
    Jeffrey interviews various attendees such as the some Microsofties (&lt;a href="http://weblogs.asp.net/scottgu"&gt;Scott Guthrie&lt;/a&gt;, &lt;a href="http://devhawk.net"&gt;Harry Pierson&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/gblock"&gt;Glenn Block&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/donsmith/"&gt;Don Smith&lt;/a&gt;), &lt;a href="http://codebetter.com/"&gt;CodeBetter guys&lt;/a&gt; (Greg, Jeremy, JP Boodhoo, Ian Cooper), Scott Bellware, the Israelis (Udi, Roy, Justin and Ayende), &lt;a href="http://www.martinfowler.com/"&gt;Martin Fowler&lt;/a&gt;, &lt;a href="http://www.oreillynet.com/pub/au/468"&gt;John Osborn&lt;/a&gt;, &lt;a href="http://jamesshore.com/"&gt;Jim Shore&lt;/a&gt;, etc on what ALT.NET means to them and why they came.&lt;/li&gt;
&lt;/ul&gt;
&lt;a href="http://codebetter.com/blogs/david_laribee"&gt;Dave Laribee&lt;/a&gt; also has a ton of video as well.  Most recently, the &lt;a href="http://en.wikipedia.org/wiki/Fishbowl_%28conversation%29"&gt;Fishbowl conversation&lt;/a&gt; about the &lt;a href="http://en.wikipedia.org/wiki/Polyglot_%28computing%29"&gt;polyglot programmer&lt;/a&gt; has been posted &lt;a href="http://codebetter.com/blogs/david_laribee/archive/2008/04/22/polyglot-programmer-fishbowl.aspx"&gt;here&lt;/a&gt;.  The debate starts with &lt;a href="http://codebetter.com/blogs/jeremy.miller/default.aspx"&gt;Jeremy Miller&lt;/a&gt;, &lt;a href="http://blogs.tedneward.com/"&gt;Ted Neward&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/charlie/"&gt;Charlie Calvert&lt;/a&gt;, &lt;a href="http://hanselman.com"&gt;Scott Hanselman&lt;/a&gt; and others.  Really good conversation posted.&lt;br /&gt;
So, as you can see from the videos it was a pretty diverse crowd.  And, hey, we managed to get all of 5 women there too!  &lt;a href="http://blogs.msdn.com/peterlau/"&gt;Peter Laudati&lt;/a&gt; posted the schedule &lt;a href="http://blogs.msdn.com/peterlau/archive/2008/04/19/alt-net-open-space-seattle-schedule-grid.aspx"&gt;here&lt;/a&gt; which was initialed by all who wanted to see that particular discussion.&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt;IronRuby Session&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Since &lt;a href="http://iunknown.com"&gt;John Lam&lt;/a&gt; wasn't around on Friday for the topic submittal, I so graciously put his name in for him.  Luckily he agreed so we were good to go for the first session.  We didn't have any canned presentations which is nice.  Instead, John focused more on how far &lt;a href="http://www.ironruby.net/"&gt;IronRuby&lt;/a&gt; has yet to go.  It was interesting that he is using the &lt;a href="http://rubini.us/"&gt;Rubinius&lt;/a&gt; &lt;a href="http://rubinius.lighthouseapp.com/projects/5089/specs-overview"&gt;specs&lt;/a&gt; in order to validate IronRuby.  Also of note, it was pretty cool to see that Spec# has been used for the IronRuby compiler.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Covering Spec#&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately, the functional programming talk that I planned with Dustin Campbell was put right along side the Spec# talk, so I had to make a choice.  I picked Spec# as it was the first Open Spaces they had done.  As I said before, one of the major things I wanted to talk about was &lt;a href="http://research.microsoft.com/specsharp/"&gt;Spec#&lt;/a&gt; at ALT.NET.  Both Greg Young and I were pretty interested in getting &lt;a href="http://research.microsoft.com/~leino/"&gt;Rustan Leino&lt;/a&gt; and &lt;a href="http://research.microsoft.com/~mbarnett/"&gt;Mike Barnett&lt;/a&gt; to show off the technology to the masses.  And what better way than to show a bunch of geeks like us this technology.  Anyhow, Mike and Rustan did a really good presentation to show off Spec# to a mass audience.  For those not familiar with Spec#, I did a whole series on this on my old blog &lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/01/07/118360.aspx"&gt;here&lt;/a&gt;.  Basically, the intent of Spec# is to provide &lt;a href="http://en.wikipedia.org/wiki/Design_by_contract"&gt;Design by Contract&lt;/a&gt; specifications in your classes and have that exposed to the outside world.  So, no more guessing about the preconditions, postconditions and invariants of your system, instead, we can be pretty explicit about it.&lt;br /&gt;
&lt;br /&gt;
The problem that they are facing is that Spec# is not just an additive to the C# compiler, instead it's a separate compiler that is compliant with the C# 2.0 specification.  The problem is that C# 3.0 introduces a few more items, albeit mostly syntactic sugar for the most part, and yet Mike is really one of the only guys doing the Spec# compiler.  So, making it C# 3.0 compliant is a pretty daunting task.  Instead, a future focus is on making language neutral pieces available to all .NET languages just as we saw briefly in the System.Core.dll assembly under the Microsoft.Contracts namespace.  The point of inviting them was to help bring their cause to a wider audience.  &lt;a href="http://www.microsoft.com/presspass/exec/techfellow/Hejlsberg/default.mspx"&gt;Anders Hejlsberg&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/madst/"&gt;Mads Torgersen&lt;/a&gt; need to put this on their mind as to how to incorporate, and I'll make sure it's widely known.&lt;br /&gt;
&lt;br /&gt;
It was great to see &lt;a href="http://hanselman.com"&gt;Scott Hanselman&lt;/a&gt; quite excited about the technology and hopefully you'll see more of it from him soon.  Also, stay tuned to &lt;a href="http://infoq.com"&gt;InfoQ&lt;/a&gt; for more Spec# related items as well.  I intend to cover things again shortly to talk about some other new things in Spec# as well as the new release.  Stay tuned for that...&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;ASP.NET MVC&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://haacked.com"&gt;Phil Haack&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/brada/"&gt;Brad Abrams&lt;/a&gt; hosted a discussion on &lt;a href="http://asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt; which was pretty positive overall.  There has been a number, around 5% that Microsoft has been throwing out there as a number of people that would be adopting ASP.NET MVC over traditional web forms.  The audience was rightly skeptical of such a number and wish that they would cut it out.  Instead, it could have the effect of scaring away people from adopting this framework as their choice for ASP.NET web applications.  I can totally understand that the numbers could be there due to the ISV market which make controls for ASP.NET web forms which is something that the MVC framework doesn't support.  Another request was to support open source javascript frameworks better.  But overall, Phil and Brad were pretty receptive and it was an overall positive experience.&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt;Are We Innovating?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Scott Hanselman convened a talk asking "Are We Innovating or Are We Just Porting?" in which that very question was asked.  If you look at the open source frameworks that exist within the .NET space, it's not hard to see what he's talking about:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;JUnit =&amp;gt; NUnit, MbUnit, xUnit.net&lt;/li&gt;
    &lt;li&gt;Hibernate =&amp;gt; NHibernate&lt;/li&gt;
    &lt;li&gt;Spring =&amp;gt; Spring.NET&lt;/li&gt;
    &lt;li&gt;Ruby on Rails =&amp;gt; MonoRail&lt;/li&gt;
    &lt;li&gt;jMock =&amp;gt; NMock, Rhino Mocks, Moq&lt;/li&gt;
    &lt;li&gt;And the list goes on...&lt;/li&gt;
&lt;/ul&gt;
But when you look at the list the other way around, we really don't see it going the other way.  Is it because that in the Java world, frameworks weren't provided by Sun as they were for Microsoft?  Or was it something else?  The answer of course isn't easy and maybe it's not in the frameworks area that we need to look.  For example such applications as Paint.NET is truly innovative in my opinion.  I wouldn't have half the picture content on this blog as easily without it.  Also, some open source blogging engines work quite well as well.  So, there is innovation, but if you look to recent times, have we caught up?&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;To Be Continued...&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/04/22/121513.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/04/22/121513.aspx" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121513"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121513" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/121513.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/04/22/121513.aspx</guid>
            <pubDate>Tue, 22 Apr 2008 23:14:41 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/121513.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/04/22/121513.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/121513.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/121513.aspx</trackback:ping>
        </item>
        <item>
            <title>Singularity - C# OS Released on CodePlex</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/03/11/120477.aspx</link>
            <description>&lt;span style="font-weight: bold;"&gt;Update:  If you want the .iso I used for the VPC, check it out &lt;/span&gt;&lt;a href="http://cid-102e0d11b5a19652.skydrive.live.com/self.aspx/Public/Tiny.Prototype.LegacyPC.MarkSweep.Min.MarkSweep.iso" style="font-weight: bold;"&gt;here&lt;/a&gt;&lt;span style="font-weight: bold;"&gt; on my &lt;/span&gt;&lt;a href="http://skydrive.live.com" style="font-weight: bold;"&gt;SkyDrive&lt;/a&gt;&lt;span style="font-weight: bold;"&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
During my research and posts about &lt;a mce_href="http://geekswithblogs.net/Podwysocki/archive/2008/01/07/118360.aspx" href="http://geekswithblogs.net/Podwysocki/archive/2008/01/07/118360.aspx"&gt;Design by Contract and Spec#&lt;/a&gt; and my interactions with folks from Microsoft Research, I came across &lt;a mce_href="http://en.wikipedia.org/wiki/Microsoft_Singularity" href="http://en.wikipedia.org/wiki/Microsoft_Singularity"&gt;Singularity OS&lt;/a&gt;, an operating system written in an offshoot language based upon C#.  In that time, I realized that the Singularity team extended &lt;a mce_href="http://www.codeplex.com/singularity/" href="http://www.codeplex.com/singularity/"&gt;Spec#&lt;/a&gt; and the &lt;a href="http://en.wikipedia.org/wiki/Design_by_contract"&gt;Design by Contract &lt;/a&gt;and &lt;a href="http://en.wikipedia.org/wiki/Static_code_analysis"&gt;static verification&lt;/a&gt; pieces of it into a new language called &lt;a href="http://en.wikipedia.org/wiki/Sing_sharp"&gt;Sing#&lt;/a&gt;.  &lt;br /&gt;
&lt;br /&gt;
Fast forward to last Tuesday.  Almost five years after the start of development, it has finally been released onto &lt;a mce_href="http://www.codeplex.com/" href="http://www.codeplex.com/"&gt;CodePlex&lt;/a&gt; as an open source non-commercial academic license and can be found &lt;a mce_href="http://www.codeplex.com/singularity/" href="http://www.codeplex.com/singularity/"&gt;here&lt;/a&gt;.  After reading about it and talking with some Microsoft Research folks about it, I had to give it a shot.  That's one of the things I love about working at Microsoft is the fact that I can interact with people like these on a periodic basis.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;History of Singularity&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
During my long commute to and from work, I have the pleasure of listening to many podcasts.  Although I like the ones in the .NET space with &lt;a href="http://hanselminutes.com/" style=""&gt;Hanselminutes&lt;/a&gt; and &lt;a href="http://dotnetrocks.com/"&gt;DotNetRocks&lt;/a&gt;, I also like to venture into the Ruby and outside community where I'm pretty comfortable as well.  So, one of my absolute favorites is &lt;a href="http://www.se-radio.net/"&gt;Software Engineering Radio&lt;/a&gt; for the serious talk and geeking about languages and architecture.  Lo and behold, the latest episode, &lt;a href="http://www.se-radio.net/podcast/2008-03/episode-88-singularity-research-os-galen-hunt"&gt;Episode 88&lt;/a&gt;, covers Singularity with &lt;a href="http://research.microsoft.com/~galenh/"&gt;Galen Hunt&lt;/a&gt; where he talks with Markus, the host about the history and features of the OS.  I suggest you listen to that before we go any further.  Also, a good overview can be found &lt;a href="http://research.microsoft.com/os/singularity/publications/OSR2007_RethinkingSoftwareStack.pdf"&gt;here&lt;/a&gt; in PDF format.&lt;br /&gt;
&lt;br /&gt;
If you think about most operating systems we run today, the essence of what they are is dated back in the 1970s and C and Assembly based.  Back in 2003, Galen and team started this effort to write an operating system in managed code.  Over 90% of the system is written in a language called Sing# which is an extension of Spec# which I will get into shortly.  But, Singularity consists of three major parts, Software Isolated Processes (SIPs), contract-based channels, and manifest-based programs.&lt;br /&gt;
&lt;br /&gt;
SIPs are interesting parts of Singularity.  They provide a sandbox as it were for program execution free from meddling from outside processes.  This includes its own memory space, threads and so on.  In fact, memory and threads cannot be shared from one SIP to the other, so the vectors for malicious code are cut way down.  &lt;br /&gt;
&lt;br /&gt;
Contract-Based Channels are another interesting aspect of Singularity.  It's a built-in feature of the Sing# language which I will get to in the next section.  In short, what it provides is a quick and verifiable way of communicating between processes with messages.  To support this, the Spec# language had to be extended to support this.&lt;br /&gt;
&lt;br /&gt;
Lastly, manifest based programs are interesting because it defines the code that runs within the SIP and its behaviors.  In Singularity, there really is no such thing as Just In Time Compiling (JIT) as all code needs to be loaded into memory and statically verified before it can be executed, which is something a JIT cannot do.  But on the other side of this, it makes dynamic languages and late binding impossible as well.  So, to work around this, they devised a plan called Compile Time Reflection, so you know your dependencies beforehand and uses Dependency Injection in a way to inject the appropriate dependencies.  Really slick stuff!&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt;Sing#&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://research.microsoft.com/~leino/"&gt; Rustan Leino&lt;/a&gt; and others in Microsoft Research had already begun an effort called Spec# to provide Design by Contract features to the C# language and a static verifier to prove that code is in fact working as the contracts were written.  Just a quick aside, we're going to be lucky enough to have Rustan at &lt;a href="http://altdotnet.org/events/seattle/"&gt;ALT.NET Open Spaces, Seattle&lt;/a&gt; to talk about it and Design by Contract (Shameless Plug).  Anyhow, back to the topic at hand.  Spec# didn't have enough for the static verification that needs to happen.  So, instead, Sing# brings us Contract Based Channels for creating message declarations and a set of named protocol sets.  Any communication that crosses processes must use contract based channels.  These messages that it passes have declarations that state the number and types of arguments for each message and an optional message direction. Each state specifies the possible message sequences leading to other states in the state machine.  &lt;br /&gt;
&lt;br /&gt;
I just want to dig through some code to see exactly what that looks like:&lt;br /&gt;
&lt;br /&gt;
    class DirectoryServiceWorker&lt;br /&gt;
    {&lt;br /&gt;
        private TRef&amp;lt;DirectoryServiceContract.Exp:Start&amp;gt; epRef;&lt;br /&gt;
        private DirNode! dirNode;&lt;br /&gt;
&lt;br /&gt;
        private DirectoryServiceWorker(DirNode! dirNode,&lt;br /&gt;
                                      [Claims] DirectoryServiceContract.Exp:Start! i_ep)&lt;br /&gt;
            requires i_ep.InState(DirectoryServiceContract.Start.Value);&lt;br /&gt;
        {&lt;br /&gt;
            epRef = new TRef&amp;lt;DirectoryServiceContract.Exp:Start&amp;gt;(i_ep);&lt;br /&gt;
            this.dirNode = dirNode;&lt;br /&gt;
            base();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
If you notice from above, you can see some Spec# goodness in there including NonNull types using the ! keyword and also requires preconditions.  It's pretty well written and a lot of fun to dig through.  If you want to learn more about compilers and operating systems, now is the time to sift through the source code and get your geek hat on.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Building the Image&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
If you want to actually run Singularity, the team has provided as part of the zip file, a way to build the operating system.  You'll simply need the following:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Windows Debugging Tools&lt;/li&gt;
    &lt;li&gt;.NET Framework 1.1&lt;/li&gt;
    &lt;li&gt;Virtual PC 2007&lt;/li&gt;
    &lt;li&gt;MSBuild&lt;/li&gt;
&lt;/ul&gt;
There is a really well documented PDF file that comes as part of the download to walk you through the build procedure step by step.  Basically, you kick off an MSBuild process which builds the image and then you can mount an iso image to see the results.&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;
&lt;br /&gt;
I was able to get the results in about 10 minutes or so for the build process.  Then again, if you're running Vista, you need to be sure to launch the configure.cmd as an elevated process in order to kick things off properly.  That was the first hurdle.  But once I got that going, the rest was easy.  And I got a pretty cool result as well when I ran the VPC image.  Look at the goodness:&lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://weblogs.asp.net/blogs/podwysocki/singularity_help.png" alt="" /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt; I have played with it just yet all that much.  I'm figuring what I can do with it next.  But, that's part of my copious spare time which doesn't seem to exist much anymore.&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
I've done well with my learning plan this year to keeping to what is on my plan and not deviating from it.  Luckily languages such as Spec# and Sing# still fall into that category.  It's pretty fascinating stuff and great to get my hands on an operating system using managed code.  It's pretty impressive from the things I've read and the code I've read.  I'm only hoping that research projects such as this make a significant impact on future versions of Windows, let alone future versions of most operating systems.  Until next time... &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/03/11/120477.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/03/11/120477.aspx" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120477"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120477" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/120477.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/03/11/120477.aspx</guid>
            <pubDate>Wed, 12 Mar 2008 00:03:26 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/120477.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/03/11/120477.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/120477.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/120477.aspx</trackback:ping>
        </item>
        <item>
            <title>Design by Contract Revisited with C# and .NET</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/01/31/119165.aspx</link>
            <description>In a previous post, I talked about various attempts at frameworks that are trying to do Design By Contract (DBC) in .NET.  Many simply just come across as simple validation frameworks without the heart of DBC which is the contract.  Where is the contract?  Well, dig through my code and find out!  It's something that I've been harping on time and time again is that without transparency to the caller and callee of the contract, it's just another validation framework.  You'll hear either myself or Greg Young on that, I'm sure.&lt;br /&gt;
&lt;br /&gt;
The only approach that has worked so far has been Spec# in the .NET world.  Unfortunately, still a research product, isn't available for us to use commercially.  So, until that time in which it is thoroughly weaved into the .NET framework as a whole outside of the internals of System.Core.dll, we have to look at alternatives.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Eiffel&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Before we look at another framework, I just want to walk you through a sample of the original DBC language, Eiffel.  This gives you an idea what I'm talking about.&lt;br /&gt;
&lt;br /&gt;
my_list.do_all (agent (s: STRING)&lt;br /&gt;
     require&lt;br /&gt;
         not_void: s /= Void&lt;br /&gt;
     do&lt;br /&gt;
         s.append_character (',')&lt;br /&gt;
     ensure&lt;br /&gt;
         appended: s.count = old s.count + 1&lt;br /&gt;
     end)&lt;br /&gt;
&lt;br /&gt;
As you can see, it's clearly stated as part of the language what the requirements are, and what its return will be.  That's the really slick part about it that we don't have unless we go to &lt;a href="http://www.eiffel.com/products/envsn/features.html"&gt;Eiffel.NET&lt;/a&gt;, but it's not using the latest and greatest .NET APIs, so it's pretty much a nonstarter.  So, let's look at yet another framework.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;LinFu DesignByContract&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://plaureano.blogspot.com/"&gt;Philip Laureano&lt;/a&gt;, who has done a lot with LinFu including Aspect Oriented Programming (AOP) among other things has taken a stab at DBC for all .NET languages and not just C# which Spec# has done.  He posted the LinFu.DesignByContract2 article on &lt;a href="http://www.codeproject.com/KB/cs/LinFu_Part5.aspx"&gt;CodeProject&lt;/a&gt; that is well worth checking out.  &lt;br /&gt;
&lt;br /&gt;
Earlier, he posted one about the LinFu framework on &lt;a href="http://www.codeproject.com/KB/cs/LinFuPart1.aspx"&gt;CodeProject&lt;/a&gt; as well which includes the following:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;A simple IoC container&lt;/li&gt;
    &lt;li&gt;Design by Contract framework&lt;/li&gt;
    &lt;li&gt;Dynamic Proxy&lt;/li&gt;
    &lt;li&gt;Reflection (Mixins, Duck Typing and Multiple Dispatch)&lt;/li&gt;
    &lt;li&gt;Delegates with lambdas for universal event handling&lt;/li&gt;
&lt;/ul&gt;
But, let's get back to the DBC part, you'll remember the basic tenets of the philosophy:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;What do we expect?&lt;/li&gt;
    &lt;li&gt;What do we return?&lt;/li&gt;
    &lt;li&gt;What do we maintain?&lt;/li&gt;
&lt;/ul&gt;
We also throw in a few Eiffel constructs in terms of inheritance which are also quite important.  And they are:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;The precondition may only be weakened by inheritance&lt;/li&gt;
    &lt;li&gt;The postcondition can only be strengthened by inheritance&lt;/li&gt;
&lt;/ul&gt;
Well, enough about the basics, let's look at the framework itself.  Let's first look at a simple sample I whipped up:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;StringCollection&lt;/span&gt;&lt;br /&gt;
{&lt;br /&gt;
   &lt;span style="color: rgb(0, 0, 255);"&gt;private int &lt;/span&gt;count;&lt;br /&gt;
   &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] strings = &lt;span style="color: rgb(0, 0, 255);"&gt;new string&lt;/span&gt;[5];&lt;br /&gt;
&lt;br /&gt;
   [&lt;span style="color: rgb(0, 128, 128);"&gt;EnsureCountIncremented&lt;/span&gt;]&lt;br /&gt;
   public virtual void Add([NotNull] string value)&lt;br /&gt;
   {&lt;br /&gt;
&lt;span style="color: rgb(51, 153, 102);"&gt;        // NotNull doing&lt;/span&gt;&lt;br style="color: rgb(51, 153, 102);" /&gt;
&lt;span style="color: rgb(51, 153, 102);"&gt;        // Debug.Assert(!string.IsNullOrEmpty(value));&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(51, 153, 102);"&gt;        // Add value and redefine    &lt;/span&gt;&lt;br style="color: rgb(51, 153, 102);" /&gt;
&lt;br style="color: rgb(51, 153, 102);" /&gt;
&lt;span style="color: rgb(51, 153, 102);"&gt;        // EnsureCountIncremened  &lt;/span&gt;&lt;br style="color: rgb(51, 153, 102);" /&gt;
&lt;span style="color: rgb(51, 153, 102);"&gt;        // Debug.Assert(count == count + 1);   &lt;/span&gt;     &lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
So, what you see here is that I put a postcondition making sure that the count is incremented by one as I'm adding a string to my array.  Also, I have the precondition that my string value is not null.  But, how does that work?&lt;br /&gt;
&lt;br /&gt;
In order to do that we need to implement a few interfaces.  Let's look at the one for preconditions.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public interface&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;IMethodContract&lt;/span&gt;&lt;br /&gt;
{&lt;br /&gt;
    &lt;span style="color: rgb(0, 128, 128);"&gt;IList&amp;lt;IPrecondition&lt;/span&gt;&amp;gt; Preconditions { &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt;; }&lt;br /&gt;
    &lt;span style="color: rgb(0, 128, 128);"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0, 128, 128);"&gt;IPostcondition&lt;/span&gt;&amp;gt; Postconditions { &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt;; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public interface&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;IPrecondition &lt;/span&gt;: &lt;span style="color: rgb(0, 128, 128);"&gt;IMethodContractCheck&lt;/span&gt;&lt;br /&gt;
{&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;bool &lt;/span&gt;Check(&lt;span style="color: rgb(0, 0, 255);"&gt;object &lt;/span&gt;target, &lt;span style="color: rgb(0, 128, 128);"&gt;InvocationInfo &lt;/span&gt;info);&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;void &lt;/span&gt;ShowError(&lt;span style="color: rgb(0, 128, 128);"&gt;TextWriter &lt;/span&gt;output, &lt;span style="color: rgb(0, 0, 255);"&gt;object &lt;/span&gt;target, &lt;span style="color: rgb(0, 128, 128);"&gt;InvocationInfo &lt;/span&gt;info);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Ok, so now, I need to implement that somehow for my custom attribute.  That would look similar to this:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public sealed class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;NotNullAttribute &lt;/span&gt;: &lt;span style="color: rgb(0, 128, 128);"&gt;Attribute&lt;/span&gt;, &lt;span style="color: rgb(0, 128, 128);"&gt;IPrecondition&lt;/span&gt;&lt;br /&gt;
{&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;public bool &lt;/span&gt;Check(&lt;span style="color: rgb(0, 0, 255);"&gt;object &lt;/span&gt;target, &lt;span style="color: rgb(0, 128, 128);"&gt;InvocationInfo &lt;/span&gt;info)&lt;br /&gt;
     {&lt;br /&gt;
          &lt;span style="color: rgb(0, 0, 255);"&gt;string &lt;/span&gt;value = target &lt;span style="color: rgb(0, 0, 255);"&gt;as string&lt;/span&gt;;&lt;br /&gt;
          if(!&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.IsNullOrEmpty(&lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;))&lt;br /&gt;
               &lt;span style="color: rgb(0, 0, 255);"&gt;return true&lt;/span&gt;;&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;public void &lt;/span&gt;ShowError(&lt;span style="color: rgb(0, 128, 128);"&gt;TextWriter &lt;/span&gt;output, &lt;span style="color: rgb(0, 0, 255);"&gt;object &lt;/span&gt;target, &lt;span style="color: rgb(0, 128, 128);"&gt;InvocationInfo &lt;/span&gt;info)&lt;br /&gt;
     {&lt;br /&gt;
          output.WriteLine(&lt;span style="color: rgb(51, 153, 102);"&gt;"string value cannot be null or blank"&lt;/span&gt;);&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;public bool &lt;/span&gt;AppliesTo(&lt;span style="color: rgb(0, 0, 255);"&gt;object &lt;/span&gt;target, &lt;span style="color: rgb(0, 128, 128);"&gt;InvocationInfo &lt;/span&gt;info)&lt;br /&gt;
     {&lt;br /&gt;
          &lt;span style="color: rgb(0, 0, 255);"&gt;return &lt;/span&gt;target &lt;span style="color: rgb(0, 0, 255);"&gt;is string&lt;/span&gt;;&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;public void &lt;/span&gt;Catch(&lt;span style="color: rgb(0, 128, 128);"&gt;Exception &lt;/span&gt;ex)&lt;br /&gt;
     {&lt;br /&gt;
&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
So, it's pretty interesting and clever how this is being done.  But still without the static checking of Boogie and so on, it still falls well short of real DBC.  &lt;br /&gt;
&lt;br /&gt;
For those interested in postconditions and invariants, those are also supported through the interfaces as shown below:&lt;br /&gt;
&lt;br /&gt;
public interface IPostcondition : IMethodContractCheck&lt;br /&gt;
{&lt;br /&gt;
    void BeforeMethodCall(object target, InvocationInfo info);&lt;br /&gt;
    bool Check(object target, InvocationInfo info, object returnValue);&lt;br /&gt;
    void ShowError(TextWriter output, object target, InvocationInfo info, &lt;br /&gt;
        object returnValue);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public interface IInvariant : IContractCheck&lt;br /&gt;
{&lt;br /&gt;
    bool Check(object target, InvocationInfo info, InvariantState callState);&lt;br /&gt;
    void ShowError(TextWriter output, object target, InvocationInfo info, &lt;br /&gt;
        InvariantState callState);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
So, as I said, quite interesting and clever the way of handling the DBC concepts through interfaces.  The libraries were also written to support the Eiffel constructs of inheritance.  So, very well written I must admit.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I just began to scratch the surface with what you can do with this framework and it's very well written.  But, still at the end of the day, it's not statically checked through a Boogie and a theorem prover to ensure the contracts hold.  That's the crucial part missing in this equation.  I'm sure more will come to mind on the subject.  Until next time... &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/01/31/119165.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/01/31/119165.aspx" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119165"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119165" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/119165.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/01/31/119165.aspx</guid>
            <pubDate>Fri, 01 Feb 2008 00:32:20 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/119165.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/01/31/119165.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/119165.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/119165.aspx</trackback:ping>
        </item>
        <item>
            <title>Design by Contract and C# (without Spec#)</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/01/22/118770.aspx</link>
            <description>After finishing the mini-lecture circuit and my often viewed &lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/01/07/118360.aspx"&gt;dive into Spec#&lt;/a&gt;, I decided to see if anyone else was working in the Design By Contract (DBC) arena with C#.  &lt;a href="http://codebetter.com/blogs/gregyoung/default.aspx"&gt;Greg Young&lt;/a&gt; and I often talk about this subject and various scenarios where it would make sense, and where it wouldn't.  Hopefully we'll hear more from the Spec# team shortly about the futures.&lt;br /&gt;
&lt;br /&gt;
It turns out there are two other attempts at what Spec# does, and that's what I'm going to dive into today.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Back to Basics&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So, first, let's get back to the basics with regard to &lt;a href="http://en.wikipedia.org/wiki/Design_by_contract"&gt;Design By Contract&lt;/a&gt; and what we're trying to achieve.  Remember back in my Spec# posts, I gave a basic introduction to DBC.  If you want a more complete introduction, check out the Eiffel documentation &lt;a href="http://archive.eiffel.com/doc/manuals/technology/contract/"&gt;here&lt;/a&gt; which covers the topic in details.  As you may remember, Eiffel was designed with DBC in mind as its key feature.&lt;br /&gt;
&lt;br /&gt;
Back in 2002, Kevin McFarlane submitted an article on CodeProject called &lt;a href="http://www.codeproject.com/KB/cs/designbycontract.aspx"&gt;Design by Contract Framework&lt;/a&gt; to introduce DBC principles into a simple library  for basic needs.  This was originally for the 1.0 framework, but could easily be ported if need be.  Currently this project doesn't use generics or any of the other .NET 2.0+ features.  Anyhow, let's get into a sample of how it works.&lt;br /&gt;
&lt;br /&gt;
The class that is the heart of the operation is the Check class.  The basic listing, minus overloads, is as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 128, 128);"&gt;// Contract verifier&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public static class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;Check&lt;/span&gt;&lt;br /&gt;
{&lt;br /&gt;
     &lt;span style="color: rgb(51, 153, 102);"&gt;// Preconditions&lt;/span&gt;&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;public static bool&lt;/span&gt; Require(&lt;span style="color: rgb(0, 0, 255);"&gt;bool &lt;/span&gt;assertion) { ... } &lt;br /&gt;
&lt;br /&gt;
     &lt;span style="color: rgb(51, 153, 102);"&gt;// Postconditions&lt;/span&gt;&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;public static bool&lt;/span&gt; Ensure(&lt;span style="color: rgb(0, 0, 255);"&gt;bool &lt;/span&gt;assertion) { ... } &lt;br /&gt;
&lt;br /&gt;
     &lt;span style="color: rgb(51, 153, 102);"&gt;// Invariants&lt;/span&gt;&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;public static bool&lt;/span&gt; Invariant(&lt;span style="color: rgb(0, 0, 255);"&gt;bool &lt;/span&gt;assertion) { ... } &lt;br /&gt;
&lt;br /&gt;
     &lt;span style="color: rgb(51, 153, 102);"&gt;// Assertions&lt;/span&gt;&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;public static bool &lt;/span&gt;Assert(&lt;span style="color: rgb(0, 0, 255);"&gt;bool &lt;/span&gt;assertion) { ... } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(51, 153, 102);"&gt;// Base contract exception&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;DesignByContractException &lt;/span&gt;: &lt;span style="color: rgb(0, 128, 128);"&gt;Exception &lt;/span&gt;{ ... }&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(51, 153, 102);"&gt;// Preconditions exception&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;PreconditionException &lt;/span&gt;: &lt;span style="color: rgb(0, 128, 128);"&gt;DesignByContractException &lt;/span&gt;{ ...}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(51, 153, 102);"&gt;// Postconditions exception&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt; public class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;PostconditionException &lt;/span&gt;: &lt;span style="color: rgb(0, 128, 128);"&gt;DesignByContractException &lt;/span&gt;{ ...}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(51, 153, 102);"&gt;// Invariants exception&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;  public class &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;InvariantException &lt;/span&gt;: &lt;span style="color: rgb(0, 128, 128);"&gt;DesignByContractException &lt;/span&gt;{ ...}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(51, 153, 102);"&gt;// Assertions exception&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;   public class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;AssertionException &lt;/span&gt;: &lt;span style="color: rgb(0, 128, 128);"&gt;DesignByContractException &lt;/span&gt;{ ...}&lt;br /&gt;
&lt;br /&gt;
And a simple example using this framework in a CustomerCollection would be as such:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public void&lt;/span&gt; Add(&lt;span style="color: rgb(0, 128, 128);"&gt;Customer &lt;/span&gt;value)&lt;br /&gt;
{&lt;br /&gt;
     &lt;span style="color: rgb(51, 153, 102);"&gt;// Check precondition&lt;/span&gt;&lt;br /&gt;
     &lt;span style="color: rgb(0, 128, 128);"&gt;Check&lt;/span&gt;.Require(value != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;);&lt;br /&gt;
&lt;br /&gt;
     &lt;span style="color: rgb(51, 153, 102);"&gt;// Check for postcondition&lt;/span&gt;&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;int &lt;/span&gt;oldCount = customerList.Count;&lt;br /&gt;
     customerList.Add(value);&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;int &lt;/span&gt;newCount = customerList.Count;&lt;br /&gt;
     &lt;span style="color: rgb(0, 128, 128);"&gt;Check&lt;/span&gt;.Ensure(newCount == oldCount + 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
As you can see, it's a pretty simple implementation, but unfortunately, it requires you the developer to think extra hard about putting these things in as well as checking your invariants along the way.  Spec# or C# with the Spec# postcompiler give you that which this does not.  So, at the end of the day, it's not much more powerful than the Validator Block inside the Enterprise Library.&lt;br /&gt;
&lt;br /&gt;
What this is also missing is one of the vital pieces of DBC which is in regard to inheritance of contracts.  In an earlier post on Spec#, I covered the basics of the following:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Preconditions cannot be strengthened or modified&lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Postconditions cannot be weakened, but can be augmented with logical ANDs&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Yet Another Approach&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
What the older solution lacked was using custom attributes to decorate a given class with its contract.  &lt;a href="http://aabs.wordpress.com"&gt;Andrew Matthews&lt;/a&gt; has taken another interesting approach in a series of blog posts.  Each one of these is interesting in its own right.&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://aabs.wordpress.com/2007/10/20/lambda-functions-for-design-by-contract/"&gt;Lambda Functions with Design by Contract&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://aabs.wordpress.com/2008/01/16/complex-assertions-using-c-30/"&gt;Complex Assertions with C# 3.0&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://aabs.wordpress.com/2008/01/18/c-by-contract-using-expression-trees/"&gt;C# by Contract - Using Expression Trees&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
In this series, Andrew is trying to find ways to make C# work with Spec# like attributes.  It's an interesting concept with all the munging he's had to do.  So, here's where he started:&lt;br /&gt;
&lt;br /&gt;
First time around:&lt;br /&gt;
&lt;br /&gt;
[Requires(“arg1 &amp;gt; 10″)]&lt;br /&gt;
[Requires(“arg2 &amp;lt; 100″)]&lt;br /&gt;
[Ensures(“$after(Prop1) == $before(Prop1) + 1″)]&lt;br /&gt;
&lt;br /&gt;
As you can see, it's not very type safe, nor really verifiable with the parsing.  So, something else had to be done.  C# as a language cannot accept lambdas and other constructs within custom attributes, so this approach won't work.&lt;br /&gt;
&lt;br /&gt;
Instead, this is the newer approach with the use of extension methods&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public static void&lt;/span&gt; Require&amp;lt;&lt;span style="color: rgb(0, 128, 128);"&gt;T&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;this &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;T&lt;/span&gt; obj, &lt;span style="color: rgb(0, 128, 128);"&gt;Expression&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0, 128, 128);"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0, 128, 128);"&gt;T&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; pred)&lt;br /&gt;
{&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;var &lt;/span&gt;x = pred.Compile();&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;if &lt;/span&gt;(!x(obj))&lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;throw new&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;ContractException&lt;/span&gt;(pred.ToString());&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
This allows for such verifications as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public void&lt;/span&gt; Add(&lt;span style="color: rgb(0, 0, 255);"&gt;string &lt;/span&gt;value)&lt;br /&gt;
{&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.Require(x =&amp;gt; !&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.IsNullOrEmpty(value));&lt;br /&gt;
     ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Pretty interesting approach, but at the end of the day, is it more verifiable.  Do you have a theorem prover on this?  No, and that's the unfortunate part.  DBC isn't as useful until the contract itself is part of the method signature.  So far Spec# has been the only option to do this.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;.NET 3.5 Implementation&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As you may have noted from my series, Spec# features have already been woven into the .NET framework, in particular System.Core.dll.  Anyhow, the heart of the operation is in the Contract class.  You may note when looking through .NET Reflector, the use of the conditional attribute as follows:&lt;br /&gt;
&lt;br /&gt;
[&lt;span style="color: rgb(0, 128, 128);"&gt;Pure&lt;/span&gt;, &lt;span style="color: rgb(0, 128, 128);"&gt;Conditional&lt;/span&gt;(&lt;span style="color: rgb(51, 153, 102);"&gt;"USE_SPECSHARP_ASSEMBLY_REWRITER"&lt;/span&gt;)]&lt;br /&gt;
&lt;br /&gt;
What this particular attribute means is that it's going to run the Spec# post-processor on the given C# assembly to produce the theorem checks.  This is where the true value of Spec# comes from to be able to tell whether or not I am fulfilling my contract during compile time.  At runtime, it's less than helpful in that regard.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Some people are doing some interesting things with Design By Contract and trying to shoehorn it into the .NET framework.  Unfortunately, unless tightly integrated with the BCL, I don't think it's going to happen.  Spec# is a great tool for this and I certainly hope/expect that it will become further part of the .NET framework in future releases.&lt;br /&gt;
&lt;br /&gt;
On a side note, if you are interested in DBC and Spec#, you may be interested in the &lt;a href="http://altdotnet.org/events/seattle/"&gt;ALT.NET Open Spaces, Seattle&lt;/a&gt; which I am currently involved in organizing.  Both Greg Young and I will be there and don't be surprised to find more people interested in it as well for a session.  We hope to open registration soon and I expect it will fill up fast!&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/01/22/118770.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/01/22/118770.aspx" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118770"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118770" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/118770.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/01/22/118770.aspx</guid>
            <pubDate>Tue, 22 Jan 2008 05:58:34 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/118770.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/01/22/118770.aspx#feedback</comments>
            <slash:comments>10</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/118770.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/118770.aspx</trackback:ping>
        </item>
        <item>
            <title>DC ALT.NET Meeting 1/15/2008 Reminder</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/01/13/118513.aspx</link>
            <description>For those who missed it, our &lt;a href="http://tech.groups.yahoo.com/group/dcaltnet/"&gt;DC ALT.NET&lt;/a&gt; group will meet on January 15th at 7PM.  I'm hoping for a great turnout of passionate developers in the DC Metro area.  Hope you can make it.  Also, don't forget to join the list as we discuss more issues and our next meeting stuff.&lt;br /&gt;
&lt;br /&gt;
The meeting this month will bring ALT.NET to &lt;a href="http://www.cmap-online.org"&gt;CMAP&lt;/a&gt;.  Are you a developer who always keeps an eye out for a better way? Do you look outside the mainstream to adopt the best practices of any development community, including Open Source, Agile, Java, and Ruby communities? Are you always looking for more elegant, more simple, more maintainable solutions? If so, then you might be an ALT.NET practitioner!&lt;br /&gt;
 &lt;br /&gt;
This group follows the &lt;a href="http://en.wikipedia.org/wiki/Open_Space_Technology"&gt;Open Space Technology&lt;/a&gt; model.  In Open Space, a facilitator explains the process and then participants are invited to co-create the agenda and host their own discussion groups. &lt;br /&gt;
 &lt;br /&gt;
This model follows the four basic principles:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Whoever comes are the right people&lt;/li&gt;
    &lt;li&gt;Whatever happens is the only thing that could have&lt;/li&gt;
    &lt;li&gt;Whenever it starts is the right time&lt;/li&gt;
    &lt;li&gt;When it's over, it's over&lt;/li&gt;
&lt;/ul&gt;
Topics for discussion can include the following as well as others:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Model View Controller Pattern (ASP.NET MVC/MonoRail)&lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Inversion of Control (IoC) containers and Dependency Injection (Spring.NET/Castle Windsor/StructureMap)&lt;/li&gt;
    &lt;li&gt;O/RM Tools (NHibernate/ActiveRecord/Entity Framework/LINQ)&lt;/li&gt;
    &lt;li&gt;Test Driven Development&lt;/li&gt;
    &lt;li&gt;Domain Driven Design&lt;/li&gt;
    &lt;li&gt;Behavior Driven Development&lt;/li&gt;
    &lt;li&gt;Design by Contract and Spec# (my topic I'll be bringing)&lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Enterprise Design Patterns in .NET&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="font-weight: bold;"&gt;Time and Location:&lt;br /&gt;
&lt;/span&gt;Tuesday, January 15, 2008 7:00 PM&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt; SM Consulting&lt;/span&gt;&lt;br /&gt;
1306 Concourse Drive&lt;br /&gt;
Suite 200&lt;br /&gt;
Linthicum, MD 21090&lt;br /&gt;
&lt;br /&gt;
Come, participate, and make your voice heard!  Come meet passionate developers like yourself in the active discussion!  We are looking to host the next one in Virginia and have a roving location per month so that more people in the metro DC area can participate. &lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118513"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118513" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/118513.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/01/13/118513.aspx</guid>
            <pubDate>Mon, 14 Jan 2008 04:26:40 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/118513.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/01/13/118513.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/118513.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/118513.aspx</trackback:ping>
        </item>
        <item>
            <title>C# - vNext</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/01/11/118478.aspx</link>
            <description>I've been reading lately about what people are interested in with the next version of C#.  It's amazing to think how far the language has come from the early days.  Many of the newer features of the language with 3.0 by far have made it a better language.&lt;br /&gt;
&lt;br /&gt;
So, what did we get with the latest C# 3.0?&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Object Initializers&lt;/li&gt;
    &lt;li&gt;Automatic Properties  &lt;/li&gt;
    &lt;li&gt;Anonymous Types&lt;/li&gt;
    &lt;li&gt;Extension Methods&lt;/li&gt;
    &lt;li&gt;Lambda Expressions&lt;/li&gt;
    &lt;li&gt;LINQ&lt;/li&gt;
    &lt;li&gt;Collection Initializers&lt;/li&gt;
&lt;/ul&gt;
By far, I agree with most of &lt;a href="http://codebetter.com/blogs/jeremy.miller/archive/2008/01/02/c-vnext-take-2.aspx"&gt;Jeremy Miller's&lt;/a&gt; sentiments regarding C# vNext, including:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Mixins&lt;/li&gt;
    &lt;li&gt;Ruby-like Symbols&lt;/li&gt;
    &lt;li&gt;Hash language features&lt;/li&gt;
    &lt;li&gt;Automatic Delegation&lt;/li&gt;
&lt;/ul&gt;
I'll throw &lt;a href="http://research.microsoft.com/specsharp"&gt;Spec#&lt;/a&gt; features and Duck Typing onto the pile.  As you may note from my earlier posts, parts already exist in .NET 3.5 libraries, so it's not hard to imagine that might open up a bit.  Plus, since I've given several presentations on the matter, I'm pretty into it.  But, also some of F#'s features are great as well that I'd like to see more merging includes mutables.  A good introduction to F# can be found &lt;a href="http://cs.hubfs.net/blogs/tomasp/archive/2007/11/03/fsharp_introduction.aspx"&gt;here&lt;/a&gt;.  But, then again, why not just stick to F#?&lt;br /&gt;
&lt;br /&gt;
What might in store for C# 4.0 anyhow?  Well, if you follow &lt;a href="http://blogs.msdn.com/ericlippert"&gt;Eric Lippert&lt;/a&gt;, one of Microsoft's best bloggers, like I do, there are some things that are very interesting that he's been working on including &lt;a href="http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)"&gt;Covariance and Contravariance&lt;/a&gt; with his ten post series:&lt;br /&gt;
&lt;br /&gt;
Each of these are worth a read:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/10/16/covariance-and-contravariance-in-c-part-one.aspx"&gt;Part One&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/10/17/covariance-and-contravariance-in-c-part-two-array-covariance.aspx"&gt;Part Two: Array Covariance&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/10/19/covariance-and-contravariance-in-c-part-three-member-group-conversion-variance.aspx"&gt;Part Three: Method Group Conversion Variance&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/10/22/covariance-and-contravariance-in-c-part-four-real-delegate-variance.aspx"&gt;Part Four: Real Delegate Variance&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/10/24/covariance-and-contravariance-in-c-part-five-higher-order-functions-hurt-my-brain.aspx"&gt;Part Five: Higher Order Functions Hurt My Brain&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/10/26/covariance-and-contravariance-in-c-part-five-interface-variance.aspx"&gt;Part Six: Interface Variance&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/10/29/covariance-and-contravariance-in-c-part-seven-why-do-we-need-a-syntax-at-all.aspx"&gt;Part Seven: Why Do We Need A Syntax At All?&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/10/31/covariance-and-contravariance-in-c-part-eight-syntax-options.aspx"&gt;Part Eight: Syntax Options&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/11/02/covariance-and-contravariance-in-c-part-nine-breaking-changes.aspx"&gt;Part Nine: Breaking Changes&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/11/09/covariance-and-contravariance-in-c-part-ten-dealing-with-ambiguity.aspx"&gt;Part Ten: Dealing With Ambiguity&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
Also, could immutability be another thing coming?  If you're a follower of Domain Driven Design, you like Value Objects and Immutability.  Spec# also introduces this concept to C# as well through the use of attributes.  And since parts of Spec# covers this, it's also very likely.  Anyhow, Eric Lippert also covers this in a "hypothetical way":&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/11/13/immutability-in-c-part-one-kinds-of-immutability.aspx"&gt;Part One: Kinds of Immutability&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/12/04/immutability-in-c-part-two-a-simple-immutable-stack.aspx"&gt;Part Two: A Simple Immutable Stack&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/12/06/immutability-in-c-part-three-a-covariant-immutable-stack.aspx"&gt;Part Three: A Covariant Immutable Stack&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/12/10/immutability-in-c-part-four-an-immutable-queue.aspx"&gt;Part Four: An Immutable Queue&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/12/18/immutability-in-c-part-six-a-simple-binary-tree.aspx"&gt;Part Six: A Simple Binary Tree &lt;br /&gt;
    &lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/12/19/immutability-in-c-part-seven-more-on-binary-trees.aspx"&gt;Part Seven: More on Binary Trees&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
But, with all new features, there are diminishing returns as noted by &lt;a href="http://codebetter.com/blogs/ian_cooper/archive/2008/01/07/c-futures-diminishing-returns-and-the-scala-parachute.aspx"&gt;Ian Cooper&lt;/a&gt;.  I'd have to agree with this point.  At some point, what are these new features going to give you when other languages can do these things more naturally?  If, say C# doesn't have a certain feature, but IronRuby does, why not use IronRuby?  Also, keeping on piling on features will ultimately make the language more complex and sifting through the various answers to find the right one becomes a bit harder.&lt;br /&gt;
&lt;br /&gt;
I disagree with others like Jeremy that call for an end and stick a fork in C#.  It's not done yet and I think it holds much more promise before we call it a day. &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/01/11/118478.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/01/11/118478.aspx" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118478"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118478" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/118478.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/01/11/118478.aspx</guid>
            <pubDate>Sat, 12 Jan 2008 02:20:01 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/118478.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/01/11/118478.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/118478.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/118478.aspx</trackback:ping>
        </item>
        <item>
            <title>.NET 3.5, Design by contract and Spec# Wrapup</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/01/07/118360.aspx</link>
            <description>&lt;span style="font-weight: bold;"&gt;Update: Adding Visual Studio Integration discussion&lt;br /&gt;
Update: Stay tuned for additional posts in this series as things permit&lt;br /&gt;
&lt;/span&gt; &lt;br /&gt;
Well, this is my last post in the series to wrap things up.  This will be updated as things come to mind, as they always do in a series like this.  There may have been unclear things that I will attempt to explain a little further, plus clarify and explore new things.&lt;br /&gt;
&lt;br /&gt;
Let's get caught up from the series:&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2007/12/10/117542.aspx"&gt;Part 1: Spec# introduction&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2007/12/12/117613.aspx"&gt;Part 2: Method Contracts (Preconditions/Postconditions)&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2007/12/16/117755.aspx"&gt;Part 3: Invariants&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2007/12/28/118045.aspx"&gt;Part 4: Object Ownership/Assertions &amp;amp; Assumptions&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/01/04/118226.aspx"&gt;Part 5: Frame Conditions/Inheritance/Boogie&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/01/06/118311.aspx"&gt;Part 6: Implementing a non-null string collection in Spec#&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Now let's go over some topics I may have missed earlier:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Constructor behavior&lt;/li&gt;
    &lt;li&gt;Pure methods&lt;/li&gt;
    &lt;li&gt;Immutables&lt;/li&gt;
    &lt;li&gt;Visual Studio Integration with C#&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="font-weight: bold;"&gt;Constructor Behavior&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
When using non-null types in your Spec# code, you need to be careful about when your object is initialized.  In .NET, the order of the calling of constructors is non-deterministic, meaning that the base constructor may be called before the super class's.  In Spec#, if you have a non-null field declared, you must initialize it, so therefore you need to control the order in which the constructors are called.  Fortunately, Spec# gives you that capability, and allows you to call the base constructor at any time during the constructor of your superclass through the use of the &lt;span style="font-weight: bold;"&gt;base &lt;/span&gt;keyword.  Below is an example of that:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;NonNullStringCollection&lt;/span&gt;&lt;br /&gt;
{&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;private &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string!&lt;/span&gt;&amp;gt;! strings;&lt;br /&gt;
&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;public &lt;/span&gt;NonNullStringCollection()&lt;br /&gt;
     {&lt;br /&gt;
          strings = &lt;span style="color: rgb(0, 0, 255);"&gt;new &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string!&lt;/span&gt;&amp;gt;();&lt;br /&gt;
          &lt;span style="color: rgb(0, 128, 128);"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color: rgb(51, 153, 102);"&gt;"Before base constructor"&lt;/span&gt;);&lt;br /&gt;
          &lt;span style="color: rgb(0, 0, 255);"&gt;base&lt;/span&gt;(); &lt;span style="color: rgb(51, 153, 102);"&gt;// Must call this after initializing all non-null fields&lt;/span&gt;&lt;br /&gt;
          &lt;span style="color: rgb(0, 128, 128);"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color: rgb(51, 153, 102);"&gt;"After base constructor"&lt;/span&gt;);&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
So, unlike C# and others, we have the ability to control the flow of our constructors.  By this, it is pretty powerful as we need to do this.  How does it look like in IL where I'll highlight where it verifies the call of the constructor&lt;br /&gt;
.method public hidebysig specialname rtspecialname instance void .ctor() cil managed&lt;br /&gt;
{&lt;br /&gt;
    .maxstack 8&lt;br /&gt;
    L_0000: ldarg.0 &lt;br /&gt;
    L_0001: newobj instance void [mscorlib]System.Collections.Generic.List`1&amp;lt;string modopt([System.Compiler.Runtime]Microsoft.Contracts.NonNullType)&amp;gt;::.ctor()&lt;br /&gt;
    L_0006: stfld class [mscorlib]System.Collections.Generic.List`1&amp;lt;string modopt([System.Compiler.Runtime]Microsoft.Contracts.NonNullType)&amp;gt; modopt([System.Compiler.Runtime]Microsoft.Contracts.NonNullType) SpecSharpSample.NonNullStringCollection::data&lt;br /&gt;
    L_000b: ldstr "Before base constructor"&lt;br /&gt;
    L_0010: call void [System]System.Diagnostics.Debug::WriteLine(string)&lt;br /&gt;
    L_0015: ldarg.0 &lt;br /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;    L_0016: call instance void [mscorlib]System.Object::.ctor()&lt;/span&gt;&lt;br /&gt;
    L_001b: ldstr "After base constructor"&lt;br /&gt;
    L_0020: call void [System]System.Diagnostics.Debug::WriteLine(string)&lt;br /&gt;
    L_0025: ret &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
If you look at the C# version through Reflector, you'll notice no difference whatsoever:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public &lt;/span&gt;NonNullStringCollection()&lt;br /&gt;
{&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.data = &lt;span style="color: rgb(0, 0, 255);"&gt;new &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string modopt&lt;/span&gt;(&lt;span style="color: rgb(0, 128, 128);"&gt;NonNullType&lt;/span&gt;)&amp;gt;();&lt;br /&gt;
    &lt;span style="color: rgb(0, 128, 128);"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color: rgb(51, 153, 102);"&gt;"Before base constructor"&lt;/span&gt;);&lt;br /&gt;
    &lt;span style="color: rgb(0, 128, 128);"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color: rgb(51, 153, 102);"&gt;"After base constructor"&lt;/span&gt;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Pure Methods&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
If you want to call a method in a specification, then the method you call must be pure, which means it has no effect on the state of objects allocated at the time the method is called.  In order for a method to be considered pure, it must be marked with the &lt;span style="font-weight: bold;"&gt;PureAttribute&lt;/span&gt;, &lt;span style="font-weight: bold;"&gt;ConfinedAttribute &lt;/span&gt;or &lt;span style="font-weight: bold;"&gt;StateIndependentAttribute &lt;/span&gt;in the Microsoft.Contracts namespace.  In order to do this, it's rather easy:&lt;br /&gt;
&lt;br /&gt;
[&lt;span style="color: rgb(0, 128, 128);"&gt;Pure&lt;/span&gt;]&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public void&lt;/span&gt; DoesNotModifyState() { ... }&lt;br /&gt;
&lt;br /&gt;
All three of the above attributes mark the method as pure.  It also declares what the method may read, so let's look at that below:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;span style="font-weight: bold;"&gt;PureAttribute &lt;/span&gt;- this method may read anything&lt;/li&gt;
    &lt;li&gt;&lt;span style="font-weight: bold;"&gt;ConfinedAttribute &lt;/span&gt;- this method can only read the state of the receiver object and its representation objects&lt;/li&gt;
    &lt;li&gt;&lt;span style="font-weight: bold;"&gt;StateIndependentAttribtue &lt;/span&gt;- this method does not read any mutable part of the heap.&lt;/li&gt;
&lt;/ul&gt;
Over time, it's the plan of the team to migrate to just a simple &lt;span style="font-weight: bold;"&gt;PureAttribute &lt;/span&gt;and I'm not sure as of this writing if that is done.  The default read permission is set to the &lt;span style="font-weight: bold;"&gt;ConfinedAttribute&lt;/span&gt;, so until the name change is complete, it's best to use that one.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Immutables&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Some objects in the .NET framework will remain "peer consistent" forever once their constructor has finished.  Recall back to the ownership and invariants discussion for that definition.  If a type is marked with the ImmutableAttribute, then the fields and such are not allowed to be modified once it has left the constructor.  To think about these, think of such objects as DateTime, Guid and other value objects, by the fact that you cannot modify them once they have been created.&lt;br /&gt;
&lt;br /&gt;
[&lt;span style="color: rgb(0, 128, 128);"&gt;Immutable&lt;/span&gt;]&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public class&lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;Coordinate&lt;/span&gt;&lt;br /&gt;
{&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;public &lt;/span&gt;Coordinate()&lt;br /&gt;
     {&lt;br /&gt;
          &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.longitude = LongitudeMinValue;&lt;br /&gt;
          &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.latitude = LatitudeMaxValue;&lt;br /&gt;
          &lt;span style="color: rgb(0, 0, 255);"&gt;base&lt;/span&gt;();&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;public &lt;/span&gt;Coordinate(&lt;span style="color: rgb(0, 0, 255);"&gt;double &lt;/span&gt;latitude, &lt;span style="color: rgb(0, 0, 255);"&gt;double &lt;/span&gt;longitude)&lt;br /&gt;
     {&lt;br /&gt;
          &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.longitude = longitude;&lt;br /&gt;
          &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.latitude = latitude;&lt;br /&gt;
          &lt;span style="color: rgb(0, 0, 255);"&gt;base&lt;/span&gt;();&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     &lt;span style="color: rgb(0, 0, 255);"&gt;public &lt;/span&gt;Coordinate Add(&lt;span style="color: rgb(0, 0, 255);"&gt;double &lt;/span&gt;latitude, &lt;span style="color: rgb(0, 0, 255);"&gt;double &lt;/span&gt;longitude)&lt;br /&gt;
     {&lt;br /&gt;
          &lt;span style="color: rgb(0, 0, 255);"&gt;return new&lt;/span&gt; Coordinate(&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.latitude + latitude, longitude + &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.longitude);&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
As you can note, I'm not changing this after I've finished constructing them.  I don't mean Value Objects in the DDD sense of the word, although it could possibly apply here as well when it comes to Entities versus Value Objects.  Anyhow, by default, these value objects are peer consistent.  The String class is immutable, so your program can always invoke methods on strings because since it is always immutable, it will always be peer consistent.&lt;br /&gt;
&lt;br /&gt;
In order to make your own objects immutable, you need to make sure it has no peers.  The static verifier, Boogie, checks to make sure no expose operations (&lt;span style="font-weight: bold;"&gt;expose &lt;/span&gt;keyword) is applied in the class as well.  Fields using the &lt;span style="font-weight: bold;"&gt;PeerAttribute &lt;/span&gt;are not allowed in immutable classes.  Also, there is no need to own an immutable object, since the reason for owning an object is to keep it peer consistent, and by default, immutable objects are peer consistent.&lt;br /&gt;
&lt;br /&gt;
There are three restrictions you must note when using an immutable object.&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;A Constructor of an immutable class must end by calling its base constructor.&lt;/li&gt;
    &lt;li&gt;Can only be declared if the base class is also immutable&lt;/li&gt;
    &lt;li&gt;A class or interface that derives from an immutable type must also be declared immutable.&lt;/li&gt;
&lt;/ul&gt;
Let's wrap this up with pure methods.  An immutable class can only invoke pure methods on its fields due to the state of the object not being allowed to change.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Visual Studio Integration with C#&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
When you install Spec# for Visual Studio 2005, by default it will install the project templates for Spec#, which includes the standard stuff plus a few extras including:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Class Library&lt;/li&gt;
    &lt;li&gt;Windows Application&lt;/li&gt;
    &lt;li&gt;Console Application&lt;/li&gt;
    &lt;li&gt;Sample Projects
    &lt;ul&gt;
        &lt;li&gt;ArrayList&lt;/li&gt;
        &lt;li&gt;Bag&lt;/li&gt;
        &lt;li&gt;Subclass with Invariant&lt;/li&gt;
        &lt;li&gt;Use Mscorlib contracts&lt;/li&gt;
    &lt;/ul&gt;
    &lt;/li&gt;
&lt;/ul&gt;
Now when you choose to use the Spec# templates, you give up a lot of the C# features that you have come to love.  This also hurts especially when using a tool such as Resharper to make me a productive developer.  You also give up auto-indentation as well, so if you want it, you do it yourself!&lt;br /&gt;
&lt;br /&gt;
But, on the positive side of things, you get the feedback from the static verifier to give you the red and green squigglies that display not only syntax errors, but also theorem prover errors coming from Boogie.  How cool is that?  Also, as I mentioned in a previous post, you get Intellisense to display the contracts of other classes as you highlight them.&lt;br /&gt;
&lt;br /&gt;
But, say for instance, you still want the rich environment of C# to do Spec#.  Well, you can do that, too.  In my first post in the series, I alluded to the fact that you could do Spec# in C# but to comment it out so that C# doesn't detect it, but Spec# will.&lt;br /&gt;
&lt;br /&gt;
To make a non-liar out of me, create a new C# project, and right click on the project and go to properties and you should see this following screen:&lt;br /&gt;
&lt;br /&gt;
&lt;img alt="C# with Spec# Contracts" src="http://geekswithblogs.net/images/geekswithblogs_net/Podwysocki/4686/r_SpecSharp_Contracts.png" /&gt;&lt;br /&gt;
&lt;br /&gt;
This screen allows you to do compile time checks on your code as you build it.  First, the project will build in C#, and then hand it off to Spec# for your post-compilation.  It's probably a similar process to what the BCL team did when they incorporated the Microsoft.Contracts namespace into System.Core.dll.&lt;br /&gt;
&lt;br /&gt;
To use these Spec# contracts in your C# code, it's as simple as commenting out your contracts with this:&lt;br /&gt;
/*^ Do Spec# thing here; ^*/&lt;br /&gt;
&lt;br /&gt;
Below is a quick example of this:&lt;br /&gt;
&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;NonNullStringCollection&lt;/span&gt;&lt;br /&gt;
{&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;private &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(51, 153, 102);"&gt;/*^!^*/&lt;/span&gt;&amp;gt;&lt;span style="color: rgb(51, 153, 102);"&gt;/*^!^*/&lt;/span&gt; strings;&lt;br /&gt;
&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;public &lt;/span&gt;NonNullStringCollection()&lt;br /&gt;
    {&lt;br /&gt;
        strings = new List&amp;lt;string/*^!^*/&amp;gt;();&lt;br /&gt;
        &lt;span style="color: rgb(51, 153, 102);"&gt;/*^base();^*/&lt;/span&gt;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;public void&lt;/span&gt; Add(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(51, 153, 102);"&gt;/*^!^*/&lt;/span&gt; value)&lt;br /&gt;
        &lt;span style="color: rgb(51, 153, 102);"&gt;/*^requires value != null;^*/&lt;/span&gt;&lt;br /&gt;
       &lt;span style="color: rgb(51, 153, 102);"&gt; /*^ensures Count == old(Count) + 1;^*/&lt;/span&gt;&lt;br /&gt;
    {&lt;br /&gt;
        strings.Add(value);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;public int&lt;/span&gt; Count&lt;br /&gt;
    {&lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt;&lt;br /&gt;
            &lt;span style="color: rgb(51, 153, 102);"&gt;/*^ensures result &amp;gt;= 0; ^*/&lt;/span&gt;&lt;br /&gt;
        {&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;return &lt;/span&gt;strings.Count;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Let's look at the constructor to make sure our base constructor gets called last:&lt;br /&gt;
&lt;br /&gt;
    .method public hidebysig specialname rtspecialname instance void .ctor() cil managed&lt;br /&gt;
    {&lt;br /&gt;
        .maxstack 8&lt;br /&gt;
        L_0000: ldarg.0 &lt;br /&gt;
        L_0001: newobj instance void [mscorlib]System.Collections.Generic.List`1&amp;lt;string modopt([System.Compiler.Runtime]Microsoft.Contracts.NonNullType)&amp;gt;::.ctor()&lt;br /&gt;
        L_0006: stfld class [mscorlib]System.Collections.Generic.List`1&amp;lt;string modopt([System.Compiler.Runtime]Microsoft.Contracts.NonNullType)&amp;gt; modopt([System.Compiler.Runtime]Microsoft.Contracts.NonNullType) NonNullTypes.NonNullStringCollection::strings&lt;br /&gt;
        L_000b: ldarg.0 &lt;br /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;        L_000c: call instance void [mscorlib]System.Object::.ctor()&lt;/span&gt;&lt;br /&gt;
        L_0011: ret &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
If you try compiling without marking base(); in the constructor, you might notice it right at the top of the method call.  Also, let's take a look at the resulting C# created for the Add Method:&lt;br /&gt;
&lt;br /&gt;
[Requires("::!=(optional([System.Compiler.Runtime]Microsoft.Contracts.NonNullType,string),string){$1,null}", Filename=@"E:\Work\NonNullTypes\NonNullStringCollection.cs", StartLine=0x12, StartColumn=0x19, EndLine=0x12, EndColumn=0x26, SourceText="value != null"), Ensures(@"::==(i32,i32){this@NonNullTypes.NonNullStringCollection::get_Count{},::+(i32,i32){\old(this@NonNullTypes.NonNullStringCollection::get_Count{}),1}}", Filename=@"E:\Work\NonNullTypes\NonNullStringCollection.cs", StartLine=0x13, StartColumn=0x18, EndLine=0x13, EndColumn=0x2f, SourceText="Count == old(Count) + 1")]&lt;br /&gt;
public void Add(string modopt(NonNullType) value)&lt;br /&gt;
{&lt;br /&gt;
    int old(Count);&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
        if (value == null)&lt;br /&gt;
        {&lt;br /&gt;
            throw new ArgumentNullException("value");&lt;br /&gt;
        }&lt;br /&gt;
        if (value == null)&lt;br /&gt;
        {&lt;br /&gt;
            throw new RequiresException("Precondition 'value != null' violated from method 'NonNullTypes.NonNullStringCollection.Add(optional(Microsoft.Contracts.NonNullType) System.String)'");&lt;br /&gt;
        }&lt;br /&gt;
        old(Count) = this.Count;&lt;br /&gt;
    }&lt;br /&gt;
    catch (ContractMarkerException)&lt;br /&gt;
    {&lt;br /&gt;
        throw;&lt;br /&gt;
    }&lt;br /&gt;
    this.strings.Add(value);&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
        if (this.Count != (old(Count) + 1))&lt;br /&gt;
        {&lt;br /&gt;
            throw new EnsuresException("Postcondition 'Count == old(Count) + 1' violated from method 'NonNullTypes.NonNullStringCollection.Add(optional(Microsoft.Contracts.NonNullType) System.String)'");&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    catch (ContractMarkerException)&lt;br /&gt;
    {&lt;br /&gt;
        throw;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So, as you can note, there are plenty more opportunities to dig deeper and I hope you all get the bug to do so.  If I missed anything, let me know!  I would love to use such a thing in production, but it's not designed for such right now.  Also, the licensing states that it's for academic uses only at this point.  But, who knows what the future holds for this.  Design, mentor and inspire!&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/01/07/118360.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/01/07/118360.aspx" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118360"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118360" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/118360.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/01/07/118360.aspx</guid>
            <pubDate>Tue, 08 Jan 2008 04:07:47 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/118360.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/01/07/118360.aspx#feedback</comments>
            <slash:comments>7</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/118360.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/118360.aspx</trackback:ping>
        </item>
        <item>
            <title>.NET 3.5, Design by contract and Spec# Part 6</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/01/06/118311.aspx</link>
            <description>&lt;span style="font-weight: bold;"&gt;Updates:&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/01/07/118360.aspx"&gt;Part7: Spec# Wrapup&lt;/a&gt;&lt;br /&gt;
&lt;/span&gt; &lt;br /&gt;
On an ongoing coverage of Spec#, I've decided to post some of the actual results of a sample Spec# class and what the results look like in C# and even IL.&lt;br /&gt;
&lt;br /&gt;
Let's get caught up to the previous posts before we continue:&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2007/12/10/117542.aspx"&gt;Part 1: Spec# introduction&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2007/12/12/117613.aspx"&gt;Part 2: Method Contracts (Preconditions/Postconditions)&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2007/12/16/117755.aspx"&gt;Part 3: Invariants&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2007/12/28/118045.aspx"&gt;Part 4: Object Ownership/Assertions &amp;amp; Assumptions&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/01/04/118226.aspx"&gt;Part 5: Frame Conditions/Inheritance/Boogie&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
By the way, I may have failed to mention that there is a great DotNetRocks broadcast with Rustan Leino, the lead researcher on Spec# which is well worth a listen and can be found &lt;a href="http://www.dotnetrocks.com/default.aspx?showNum=237"&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Anyhow, let's start with a simple example of a NonNullStringCollection.  I'll be a little lazy and use an ArrayList behind the scenes, but let's look for how you handle the method contracts.  We'll use preconditions and postconditions, non null types and so on.&lt;br /&gt;
&lt;br style="color: rgb(0, 0, 0);" /&gt;
&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using &lt;/span&gt;System;&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;using &lt;/span&gt;System.Collections;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;namespace &lt;/span&gt;SpecSharpSample&lt;br /&gt;
{&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;NonNullStringCollection&lt;/span&gt;&lt;br /&gt;
    {&lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;private &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;ArrayList&lt;/span&gt;! data;&lt;br /&gt;
    &lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;public &lt;/span&gt;NonNullStringCollection()&lt;br /&gt;
        {&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.data = &lt;span style="color: rgb(0, 0, 255);"&gt;new &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;ArrayList&lt;/span&gt;();&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;base&lt;/span&gt;(); &lt;span style="color: rgb(51, 153, 102);"&gt;// Call this after assigning our non-null fields&lt;/span&gt;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;public int&lt;/span&gt; Add(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;span style="color: rgb(0, 0, 0);"&gt;!&lt;/span&gt; &lt;/span&gt;value)&lt;br /&gt;
             &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;value != &lt;span style="color: rgb(0, 0, 255);"&gt;null otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;ArgumentNullException&lt;/span&gt;;&lt;br /&gt;
             &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;!&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.IsReadOnly &lt;span style="color: rgb(0, 0, 255);"&gt;otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;InvalidOperationException&lt;/span&gt;;&lt;br /&gt;
             &lt;span style="color: rgb(0, 0, 255);"&gt;ensures &lt;/span&gt;Count &amp;gt; 0;        &lt;br /&gt;
        {&lt;br /&gt;
            return &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.data.Add(value);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;public void &lt;/span&gt;AddRange(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[]! value)&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;value != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;forall&lt;/span&gt;{&lt;span style="color: rgb(0, 0, 255);"&gt;int &lt;/span&gt;i &lt;span style="color: rgb(0, 0, 255);"&gt;in &lt;/span&gt;(0:value.Length); value[i] != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;} &lt;span style="color: rgb(0, 0, 255);"&gt;otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;ArgumentNullException&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 0);"&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;!&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.IsReadOnly &lt;span style="color: rgb(0, 0, 255);"&gt;otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;InvalidOperationException&lt;/span&gt;;&lt;br /&gt;
        {&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.data.AddRange(value);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;public void&lt;/span&gt; Clear()&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;!&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.IsReadOnly &lt;span style="color: rgb(0, 0, 255);"&gt;otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;InvalidOperationException&lt;/span&gt;;&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;ensures &lt;/span&gt;Count == 0;&lt;br /&gt;
        {&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.data.Clear();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;public bool&lt;/span&gt; Contains(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;! value)&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;value != &lt;span style="color: rgb(0, 0, 255);"&gt;null otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;ArgumentNullException&lt;/span&gt;;&lt;br /&gt;
        {&lt;br /&gt;
            return &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.data.Contains(value);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;public void&lt;/span&gt; CopyTo(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[]! array, &lt;span style="color: rgb(0, 0, 255);"&gt;int &lt;/span&gt;index)&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;array != &lt;span style="color: rgb(0, 0, 255);"&gt;null otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;ArgumentNullException&lt;/span&gt;;&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;index &amp;gt;=0 &amp;amp;&amp;amp; index &amp;lt; Count &lt;span style="color: rgb(0, 0, 255);"&gt;otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;ArgumentOutOfRangeException&lt;/span&gt;;&lt;br /&gt;
        {&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.data.CopyTo(array, index);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;public void&lt;/span&gt; Insert(&lt;span style="color: rgb(0, 0, 255);"&gt;int &lt;/span&gt;index, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;! value)&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;value != &lt;span style="color: rgb(0, 0, 255);"&gt;null otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;ArgumentNullException&lt;/span&gt;;&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;!&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.IsReadOnly &lt;span style="color: rgb(0, 0, 255);"&gt;otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;InvalidOperationException&lt;/span&gt;;&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;index &amp;gt;=0 &amp;amp;&amp;amp; index &amp;lt; Count &lt;span style="color: rgb(0, 0, 255);"&gt;otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;ArgumentOutOfRangeException&lt;/span&gt;;&lt;br /&gt;
        {&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.data.Insert(index, value);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;public void&lt;/span&gt; Remove(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;! value)&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;value != null &lt;span style="color: rgb(0, 0, 255);"&gt;otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;ArgumentNullException&lt;/span&gt;;&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;!&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.IsReadOnly &lt;span style="color: rgb(0, 0, 255);"&gt;otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;InvalidOperationException&lt;/span&gt;;&lt;br /&gt;
        {&lt;br /&gt;
            this.data.Remove(value);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;public void&lt;/span&gt; RemoveAt(&lt;span style="color: rgb(0, 0, 255);"&gt;int &lt;/span&gt;index)&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;index &amp;gt;=0 &amp;amp;&amp;amp; index &amp;lt; Count &lt;span style="color: rgb(0, 0, 255);"&gt;otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;ArgumentOutOfRangeException&lt;/span&gt;;&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;ensures &lt;/span&gt;Count == old(Count) - 1;&lt;br /&gt;
        {&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.data.RemoveAt(index);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;public int&lt;/span&gt; Count&lt;br /&gt;
        {&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;get &lt;/span&gt;&lt;br /&gt;
                &lt;span style="color: rgb(0, 0, 255);"&gt;ensures &lt;/span&gt;result &amp;gt;= 0;&lt;br /&gt;
            {&lt;br /&gt;
                &lt;span style="color: rgb(0, 0, 255);"&gt;return this&lt;/span&gt;.data.Count;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;public bool&lt;/span&gt; IsReadOnly&lt;br /&gt;
        {&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;get &lt;/span&gt;&lt;br /&gt;
                &lt;span style="color: rgb(0, 0, 255);"&gt;ensures &lt;/span&gt;result == &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;;&lt;br /&gt;
            {&lt;br /&gt;
                &lt;span style="color: rgb(0, 0, 255);"&gt;return false&lt;/span&gt;;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
       &lt;span style="color: rgb(0, 0, 255);"&gt; public bool&lt;/span&gt; IsSynchronized&lt;br /&gt;
        {&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt;&lt;br /&gt;
                &lt;span style="color: rgb(0, 0, 255);"&gt;ensures &lt;/span&gt;result == &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;;&lt;br /&gt;
            {&lt;br /&gt;
                &lt;span style="color: rgb(0, 0, 255);"&gt;return false&lt;/span&gt;;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;public string this&lt;/span&gt;[int index]&lt;br /&gt;
        {&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;get &lt;/span&gt;&lt;br /&gt;
              &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;index &amp;gt;=0 &amp;amp;&amp;amp; index &amp;lt; Count &lt;span style="color: rgb(0, 0, 255);"&gt;otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;ArgumentOutOfRangeException&lt;/span&gt;;&lt;br /&gt;
              &lt;span style="color: rgb(0, 0, 255);"&gt;ensures &lt;/span&gt;result != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;br /&gt;
            {&lt;br /&gt;
                &lt;span style="color: rgb(0, 0, 255);"&gt;return &lt;/span&gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;) &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.data[index];&lt;br /&gt;
            }&lt;br /&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;set &lt;/span&gt;&lt;br /&gt;
              &lt;span style="color: rgb(0, 0, 255);"&gt;requires &lt;/span&gt;index &amp;gt;=0 &amp;amp;&amp;amp; index &amp;lt; Count &lt;span style="color: rgb(0, 0, 255);"&gt;otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;ArgumentOutOfRangeException&lt;/span&gt;;&lt;br /&gt;
              &lt;span style="color: rgb(0, 0, 255);"&gt;requires value &lt;/span&gt;!= &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;br /&gt;
            {&lt;br /&gt;
                &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.data[index] = &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
As you can see, I mixed in a bunch of preconditions, postconditions and assertions.  While you are developing in Spec#, you might notice that the Intellisense for Visual Studio offers something pretty interesting.  &lt;br /&gt;
&lt;br /&gt;
&lt;img alt="Spec# Intellisense" src="http://geekswithblogs.net/images/geekswithblogs_net/Podwysocki/4686/r_SpecSharp_Intellisense.png" /&gt;&lt;br /&gt;
&lt;br /&gt;
As you may notice, this displays the method contracts for you thus making your life a little easier to fulfill the contracts.  Pretty cool, huh?&lt;br /&gt;
&lt;br /&gt;
Now, let's take a look at some of the code that gets translated by Reflector into IL.  Let's look at the Add method.  Note the preconditions and postconditions as stated in the above class.  Also, note the usage of the NonNullType as well.  I'll highlight the areas of interest below:&lt;br /&gt;
&lt;br /&gt;
.method public hidebysig instance int32 Add(string modopt([System.Compiler.Runtime]&lt;span style="background-color: rgb(255, 255, 0);"&gt;Microsoft.Contracts.NonNullType&lt;/span&gt;) 'value') cil managed&lt;br /&gt;
{&lt;br /&gt;
    .custom instance void [System.Compiler.Runtime]Microsoft.Contracts.RequiresAttribute::.ctor(string) = { string('::!=(optional([System.Compiler.Runtime]Microsoft.Contracts.NonNullType,string),string){$1,null}') Filename=string('E:\\Work\\SpecSharpSample\\Class1.ssc') StartLine=int32(0x10) StartColumn=int32(0x17) EndLine=int32(0x10) EndColumn=int32(0x24) SourceText=string('value != null') }&lt;br /&gt;
    .custom instance void [System.Compiler.Runtime]Microsoft.Contracts.RequiresAttribute::.ctor(string) = { string('::!(bool){this@SpecSharpSample.NonNullStringCollection::get_IsReadOnly{}}') Filename=string('E:\\Work\\SpecSharpSample\\Class1.ssc') StartLine=int32(0x11) StartColumn=int32(0x17) EndLine=int32(0x11) EndColumn=int32(0x27) SourceText=string('!this.IsReadOnly') }&lt;br /&gt;
    .custom instance void [System.Compiler.Runtime]Microsoft.Contracts.EnsuresAttribute::.ctor(string) = { string('::&amp;gt;(i32,i32){this@SpecSharpSample.NonNullStringCollection::get_Count{},0}') Filename=string('E:\\Work\\SpecSharpSample\\Class1.ssc') StartLine=int32(0x12) StartColumn=int32(0x16) EndLine=int32(0x12) EndColumn=int32(0x1f) SourceText=string('Count &amp;gt; 0') }&lt;br /&gt;
    .maxstack 6&lt;br /&gt;
    .locals init (&lt;br /&gt;
        [0] class [System.Compiler.Runtime]&lt;span style="background-color: rgb(255, 255, 0);"&gt;Microsoft.Contracts.ContractMarkerException&lt;/span&gt; exception,&lt;br /&gt;
        [1] int32 return value,&lt;br /&gt;
        [2] class [System.Compiler.Runtime]&lt;span style="background-color: rgb(255, 255, 0);"&gt;Microsoft.Contracts.ContractMarkerException&lt;/span&gt; SS$Contract Marker,&lt;br /&gt;
        [3] int32 SS$Display Return Local)&lt;br /&gt;
    L_0000: ldarg.1 &lt;br /&gt;
    L_0001: ldnull &lt;br /&gt;
    L_0002: beq L_000c&lt;br /&gt;
    L_0007: br L_0017&lt;br /&gt;
    L_000c: ldstr "value"&lt;br /&gt;
    L_0011: newobj instance void [mscorlib]System.ArgumentNullException::.ctor(string)&lt;br /&gt;
    L_0016: throw &lt;br /&gt;
    L_0017: ldarg.1 &lt;br /&gt;
    L_0018: ldnull &lt;br /&gt;
    L_0019: beq L_0023&lt;br /&gt;
    L_001e: br L_0029&lt;br /&gt;
    L_0023: newobj instance void [mscorlib]System.ArgumentNullException::.ctor()&lt;br /&gt;
    L_0028: throw &lt;br /&gt;
    L_0029: ldarg.0 &lt;br /&gt;
    L_002a: call instance bool SpecSharpSample.NonNullStringCollection::get_IsReadOnly()&lt;br /&gt;
    L_002f: brtrue L_0039&lt;br /&gt;
    L_0034: br L_003f&lt;br /&gt;
    L_0039: newobj instance void [mscorlib]&lt;span style="background-color: rgb(255, 255, 0);"&gt;System.InvalidOperationException&lt;/span&gt;::.ctor()&lt;br /&gt;
    L_003e: throw &lt;br /&gt;
    L_003f: leave L_0047&lt;br /&gt;
    L_0044: stloc.0 &lt;br /&gt;
    L_0045: rethrow &lt;br /&gt;
    L_0047: nop &lt;br /&gt;
    L_0048: ldarg.0 &lt;br /&gt;
    L_0049: ldfld class [mscorlib]System.Collections.ArrayList modopt([System.Compiler.Runtime]Microsoft.Contracts.NonNullType) SpecSharpSample.NonNullStringCollection::data&lt;br /&gt;
    L_004e: ldarg.1 &lt;br /&gt;
    L_004f: callvirt instance int32 [mscorlib]System.Collections.ArrayList::Add(object)&lt;br /&gt;
    L_0054: stloc.1 &lt;br /&gt;
    L_0055: br L_005a&lt;br /&gt;
    L_005a: ldarg.0 &lt;br /&gt;
    L_005b: call instance int32 SpecSharpSample.NonNullStringCollection::get_Count()&lt;br /&gt;
    L_0060: ldc.i4.0 &lt;br /&gt;
    L_0061: ble L_006b&lt;br /&gt;
    L_0066: br L_0076&lt;br /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;     L_006b: ldstr "Postcondition \'Count &amp;gt; 0\' violated from method \'SpecSharpSample.NonNullStringCollection.Add(optional(Microsoft.Contracts.NonNullType) System.String)\'"&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);" /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;     L_0070: newobj instance void [System.Compiler.Runtime]Microsoft.Contracts.EnsuresException::.ctor(string)&lt;/span&gt;&lt;br /&gt;
    L_0075: throw &lt;br /&gt;
    L_0076: nop &lt;br /&gt;
    L_0077: leave L_007f&lt;br /&gt;
    L_007c: stloc.2 &lt;br /&gt;
    L_007d: rethrow &lt;br /&gt;
    L_007f: nop &lt;br /&gt;
    L_0080: ldloc.1 &lt;br /&gt;
    L_0081: stloc.3 &lt;br /&gt;
    L_0082: ldloc.1 &lt;br /&gt;
    L_0083: ret &lt;br /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;     .try L_0000 to L_0044 catch [System.Compiler.Runtime]Microsoft.Contracts.ContractMarkerException handler L_0044 to L_0047&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);" /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;     .try L_005a to L_007c catch [System.Compiler.Runtime]Microsoft.Contracts.ContractMarkerException handler L_007c to L_007f&lt;/span&gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Now that we looked at the IL, note the exceptions throws and which time.  Now that we have done that, study the code above and check for the assertions, the preconditions and postconditions.  Let's look at a C# version.  Note that it looks very similar to that in the System.Core.dll within the Microsoft.Contracts namespace from some of the classes that we talked about in earlier posts.  Once again, I'll highlight the interesting points below.&lt;br /&gt;
&lt;br /&gt;
[&lt;span style="background-color: rgb(255, 255, 0);"&gt;Requires&lt;/span&gt;("::!=(optional([System.Compiler.Runtime]Microsoft.Contracts.NonNullType,string),string){$1,null}", Filename=@"E:\Work\SpecSharpSample\Class1.ssc", StartLine=0x10, StartColumn=0x17, EndLine=0x10, EndColumn=0x24, SourceText="value != null"), &lt;span style="background-color: rgb(255, 255, 0);"&gt;Requires&lt;/span&gt;("::!(bool){this@SpecSharpSample.NonNullStringCollection::get_IsReadOnly{}}", Filename=@"E:\Work\SpecSharpSample\Class1.ssc", StartLine=0x11, StartColumn=0x17, EndLine=0x11, EndColumn=0x27, SourceText="!this.IsReadOnly"), &lt;span style="background-color: rgb(255, 255, 0);"&gt;Ensures&lt;/span&gt;("::&amp;gt;(i32,i32){this@SpecSharpSample.NonNullStringCollection::get_Count{},0}", Filename=@"E:\Work\SpecSharpSample\Class1.ssc", StartLine=0x12, StartColumn=0x16, EndLine=0x12, EndColumn=0x1f, SourceText="Count &amp;gt; 0")]&lt;br /&gt;
public int Add(string modopt(&lt;span style="background-color: rgb(255, 255, 0);"&gt;NonNullType&lt;/span&gt;) value)&lt;br /&gt;
{&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;         if (value == null)&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);" /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;         {&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);" /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;             throw new ArgumentNullException("value");&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);" /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;         }&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);" /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;         if (value == null)&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);" /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;         {&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);" /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;             throw new ArgumentNullException();&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);" /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;         }&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);" /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;         if (this.IsReadOnly)&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);" /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;         {&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);" /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;             throw new InvalidOperationException();&lt;/span&gt;&lt;br style="background-color: rgb(255, 255, 0);" /&gt;
&lt;span style="background-color: rgb(255, 255, 0);"&gt;         }&lt;/span&gt;&lt;br /&gt;
    }&lt;br /&gt;
    catch (ContractMarkerException)&lt;br /&gt;
    {&lt;br /&gt;
        throw;&lt;br /&gt;
    }&lt;br /&gt;
    int return value = this.data.Add(value);&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
        &lt;span style="background-color: rgb(255, 255, 0);"&gt;if (this.Count &amp;lt;= 0)&lt;/span&gt;&lt;br /&gt;
        {&lt;br /&gt;
            throw new EnsuresException("Postcondition 'Count &amp;gt; 0' violated from method 'SpecSharpSample.NonNullStringCollection.Add(optional(Microsoft.Contracts.NonNullType) System.String)'");&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    catch (ContractMarkerException)&lt;br /&gt;
    {&lt;br /&gt;
        throw;&lt;br /&gt;
    }&lt;br /&gt;
    int SS$Display Return Local = return value;&lt;br /&gt;
    return return value;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, I'm pretty fascinated with Design by Contract and how it applies to .NET.  I hope that the next version of C# has this as well as other features I'll cover later.  I hope this series was informational and worthwhile as it was for me.  Develop, mentor and inspire!&lt;br /&gt;
&lt;br /&gt;
Please let me know if there is anything I missed or would like to see in this series.&lt;br /&gt;
&lt;/span&gt; &lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/01/06/118311.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/01/06/118311.aspx" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118311"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118311" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/118311.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/01/06/118311.aspx</guid>
            <pubDate>Mon, 07 Jan 2008 02:58:30 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/118311.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/01/06/118311.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/118311.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/118311.aspx</trackback:ping>
        </item>
        <item>
            <title>.NET 3.5, Design by contract and Spec# Part 5</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/01/04/118226.aspx</link>
            <description>&lt;span style="font-weight: bold;"&gt;Update:  the following updates:&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/01/06/118311.aspx" style="font-weight: bold;"&gt;Part 6: Implementing a non-null string collection&lt;/a&gt;&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/01/07/118360.aspx" style="font-weight: bold;"&gt;Part7: Spec# Wrapup&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Well, I thought I'd find some distraction from watching my Hokies losing to Kansas right now 14-17.  Boo!  Oh well, let's get back to our coverage of Spec#.  Let's get caught up to where we are so far.  Review each of these before we continue.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2007/12/10/117542.aspx"&gt;Part 1: Spec# introduction&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2007/12/12/117613.aspx"&gt;Part 2: Method Contracts (Preconditions/Postconditions)&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2007/12/16/117755.aspx"&gt;Part 3: Invariants&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2007/12/28/118045.aspx"&gt;Part 4: Object Ownership/Assertions &amp;amp; Assumptions&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
So, once again, now that we're up to date, let's move onto two of the more fun topics.  Today, we're going to cover the following:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Frame Conditions&lt;/li&gt;
    &lt;li&gt;Inheritance&lt;/li&gt;
    &lt;li&gt;Boogie&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="font-weight: bold;"&gt;Frame Conditions&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Spec# introduces a concept called frame conditions.  This concept allows you to restrict which pieces of the state that a particular method is allowed to modify.  This is specified by using the &lt;span style="font-weight: bold;"&gt;modifies &lt;/span&gt;keyword.  Let's walk through a basic example&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;Adder&lt;/span&gt;&lt;br /&gt;
{&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;private int&lt;/span&gt; sum;&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;private int&lt;/span&gt; unchangedValue;&lt;br /&gt;
    &lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;public int &lt;/span&gt;Add(&lt;span style="color: rgb(0, 0, 255);"&gt;int &lt;/span&gt;x) &lt;span style="color: rgb(0, 0, 255);"&gt;modifies &lt;/span&gt;sum;&lt;br /&gt;
    {&lt;br /&gt;
        sum += x;&lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;return &lt;/span&gt;sum;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
In the above example, I created a method called Add which is allowed to modify the state of sum, but changes to any other variables such as unchangedValue is not allowed.  The state of unchangedValue must remain the same from entry to exit.&lt;br /&gt;
&lt;br /&gt;
Interesting concept, but how likely is it that you want to expose your member variables as part of your method contract?  Instead, Spec# allows for the concept of wildcards.  This allows you to modify the fields of the object through a simple statement.  The documentation states that the ^ can be used to denote a wildcard but I cannot get it to work.  The below code should work according to the original spec:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;Adder&lt;/span&gt;&lt;br /&gt;
{&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;private int&lt;/span&gt; sum;&lt;br /&gt;
    &lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;public int&lt;/span&gt; Add(&lt;span style="color: rgb(0, 0, 255);"&gt;int &lt;/span&gt;x) &lt;span style="color: rgb(0, 0, 255);"&gt;modifies this&lt;/span&gt;^&lt;span style="color: rgb(0, 128, 128);"&gt;Adder&lt;/span&gt;;&lt;br /&gt;
    {&lt;br /&gt;
        sum += x;&lt;br /&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;return &lt;/span&gt;sum;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
What the wildcard allows is that I can modify all fields within my Adder class.  What's interesting about the wildcards is that they don't extend to aggregate objects.  Take for an example, StringCollection.  If I put a modifies wildcard on the Add method, I can modify the count and the reference to the string array, but I cannot modify the array elements.&lt;br /&gt;
&lt;br /&gt;
These frame conditions only serve as documentation as they are not enforced at runtime.  Instead, they are used by, yes, there's that word again, Boogie.  There are two reasons for this not being checked at runtime.  First is performance since the preconditions and postconditions must be checked in the heap, and second is that if you are making a transition to C#, it makes it easier not to have these as run time errors.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Inheritance of Specifications&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In Spec#, your method's contract is inherited by the method's overrides.  The run-time checks evoked by the method contract are also inherited as well.  This helps make documentation more readable than say the MSDN where we have to read the documentation about the preconditions for a particular method.&lt;br /&gt;
&lt;br /&gt;
Additional postconditions can be added to your class through the use of the &lt;span style="font-weight: bold;"&gt;ensures &lt;/span&gt;keyword.  The override can add exception causing postconditions only for those exceptions that are already covered by the throws set, meaning that you've already declared your method throws them. You are not allowed to give any additional frame conditions, instead it's best by adding a postcondition. Changes to the preconditions are also not allowed, because the callers expect the specification at the static resolution of the method to agree with the dynamic checking.&lt;br /&gt;
&lt;br /&gt;
Below is an example of adding an additional postcondition:&lt;br /&gt;
&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;Foo&lt;/span&gt;&lt;br /&gt;
{&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;public int &lt;/span&gt;Index;&lt;br /&gt;
    &lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;public virtual void &lt;/span&gt;Increment() &lt;span style="color: rgb(0, 0, 255);"&gt;ensures &lt;/span&gt;Index &amp;gt; 0;&lt;br /&gt;
    {&lt;br /&gt;
        Index++;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(0, 128, 128);"&gt;Bar &lt;/span&gt;: &lt;span style="color: rgb(0, 128, 128);"&gt;Foo&lt;/span&gt;&lt;br /&gt;
{&lt;br /&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;public override void&lt;/span&gt; Increment() &lt;span style="color: rgb(0, 0, 255);"&gt;ensures &lt;/span&gt;Index == &lt;span style="color: rgb(0, 0, 255);"&gt;old&lt;/span&gt;(Index) + 1;&lt;br /&gt;
    {&lt;br /&gt;
        Index++;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interfaces, much like classes can also have methods with specifications.  With these interfaces, you can have multiple inheritance.  Spec# combines these inherited specifications, much like the postconditions.  For the Exception throwing specifications, they must have the same throws declared or else it won't work.  Like with class inheritance, the preconditions are not combined unless they are the same as well.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Boogie&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I know it took me a while to get to Boogie, but it's one of the most important pieces of Spec#.  Boogie is a static verifier that attempts to statistically prove that a program functions correctly by translating the given Spec# program into it's own intermediate language called BoogiePL.  The BoogiePL is a simple language consisting of methods with four kinds of statements, assignments, asserts, assumes and method calls.  The BoogiePL program goes through several transformations before it is fed to a theorem prover.  Microsoft is using their own internal verifier now as part of boogie, called Z3.&lt;br /&gt;
&lt;br /&gt;
What's really nice is that it checks whether the contract is fulfilled.  If not, developers are warned at development time that they're not working conform the contract.   To use Boogie, simply go to the Spec# command prompt as installed when you installed Spec#.  Simply type Boogie and the full path to your assembly.  From there, the magic happens.  Here is a simple output:&lt;br /&gt;
&lt;br /&gt;
&lt;table width="100%" cellspacing="1" cellpadding="1" border="0" align="" style="background-color: black; color: rgb(128, 128, 128);" summary=""&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;E:\Work\Project1\bin\debug&amp;gt;boogie project1.exe&lt;br /&gt;
            Spec# Program Verifier Version 0.88, Copyright (c) 2003-2007, Microsoft.&lt;br /&gt;
 