by Michael Hodgdon posted on May 24 2010 04:14
As a software consultant I have spent multiple hours learning new languages and API's. Having experienced this process myself many times one of the things that I appreciate in a product or code library is effective documentation. Reading documentation is a crucial first step in learning any new product. However, any developer knows that when the rubber meets the road, there is one place that always falls a little bit short.
Documentation almost always falls down when you actually start to consume the methods and classes. The reason is because code is constantly evolving. Documentation is great for high level components and understanding intent. Where it fails is at the interface level. Wouldn't it be great if developers receive compile warnings if they were using your library incorrectly?
Microsoft added something call Code Contracts into .NET 4.0 that allows developers to describe the behavior of their methods and classes in a way that consumers receive real time feedback from the compiler if they are using a method or class incorrectly. The next version of MobilePipes will include Code Contract checking which will provide better documentation. Customers that are customizing MobilePipes will really appreciate this addition because it will allow you to better understand how to effectively grow the product to fit into your business needs. We are working to include all of the feedback we receive from customers into our customization interfaces to answer your commonly asked questions in real time when you are writing code.
For example, take the IModuleOperation interface in MobilePipes. This interface has the following definition:

Writing a custom module in MobilePipes involves implementing this interface. The very first thing that MobilePipes does when it receives a request is to validate the Data argument that goes into these methods. This validation consists of ensuring that the XDocument Data object contains the correct MobilePipes XML Schema. If this schema does not exist then the method will not execute. You will receive an "Invalid schema validation" message from the MobilePipes server.
With Code Contracts we can notify the developer early on in their testing code that they are passing a bad value by changing the interface to the following:

Now developers will receive an "Invalid schema validation" in their unit tests letting them know that their XML input string is incorrect. This saves lots of time deploying and debugging and shows customers how to use our product more effectively.
NOTE: Some of the code here is pseudo code and is intended to demonstrate advances in the MobilePipes product. It is not intended to be a demonstration of Code Contracts in .NET. Readers that are intestered in Code Contracts should consult Microsoft documentation. I recommend also viewing "Contract Checking and Automated Test Generation with Pex" from the PDC2008 < http://channel9.msdn.com/pdc2008/TL51/ >.
{ Happy Coding }
4231ab2a-1925-48cf-b95d-79d7e89e4f2f|0|.0
Tags: