Geeks With Blogs
Josh Reuben
·         Make Coding Assumptions Explicit and Tool Discoverable. provide a language-agnostic way to express coding assumptions in .NET programs. The contracts take the form of pre-conditions, post-conditions, and object invariants. Contracts act as checked documentation of your external and internal APIs. The contracts are used to improve testing via runtime checking, enable static contract verification, and documentation generation.
 
 
 
 
 
·         bring the advantages of design-by-contract programming to all .NET programming languages. benefits:
o   Improved testability – A) each contract acts as an oracle, giving a test run a pass/fail indication. B) automatic testing tools, such as Pex, can take advantage of contracts to generate more meaningful unit tests by filtering out meaningless test arguments that don't satisfy the pre-conditions.
o   Static verification - use contracts to reduce false positives and produce more meaningful errors.
o   API documentation - The same contracts used for runtime testing and static verification can also be used to generate better API documentation, such as which parameters need to be non-null, etc.
·         consists of a [library|Contract Language] for writing pre-conditions, post-conditions, and object invariants. The use of a library has the advantage that all .NET languages can immediately take advantage of contracts. There is no need to write a special parser or compiler. Furthermore, the respective language compilers naturally check the contracts for well-formedness (type checking and name resolution) and produce a compiled form of the contracts as MSIL. Authoring contracts in Visual Studio allows programmers to take advantage of the standard intellisense provided by the language services.
·         Previous approaches based on .NET attributes fall far short as they neither provide an expressive enough medium, nor can they take advantage of compile-time checks.
·         tools: 1) cccheck, a static checker that verifies contracts at compile-time. 2) ccrewrite, for generating runtime checking from the contracts. The plan is to add further tools for Automatic API documentation generation & Intellisense integration
·         Contracts are expressed using static method calls at method entries. Tools take care to interpret these declarative contracts in the right places. These methods are found in the System.Diagnostics.Contracts namespace.
o   Contract.Requires takes a boolean condition and expresses a pre-condition of the method. A pre-condition must be true on entry to the method. It is the caller's responsibility to make sure the pre-condition is met.
o   Contract.Ensures takes a boolean condition and expresses a post-condition of the method. A post-condition must be true at all normal exit points of the method. It is the implementation's responsibility that the post-condition is met.
·         Download - At the moment, only a release for VS2008 with an academic license is available here.
 
 The devlab version for VS2010 is coming soon. 
 
 
 
 
 
 
 
 
 
 
 
Posted on Sunday, November 2, 2008 9:32 PM NET 5.0 , Meta-Programming | Back to top


Comments on this post: Code Contracts - the dark horse of the PDC

# re: Code Contracts - the dark horse of the PDC
Requesting Gravatar...
It is a nice app that features unique content. - Marla Ahlgrimm
Left by Shane Michaels on Dec 22, 2016 6:24 AM

Your comment:
 (will show your gravatar)


Copyright © JoshReuben | Powered by: GeeksWithBlogs.net