Sunday, February 19, 2012

Be explicit, use Code Contracts.

What is code contract?
It is a latest set of tools and library from Microsoft that provides optimised way of validate parameters , return values and object state.

Code contract are new to developer , most of the time developer use IF-THEN-ELSE Throw Exception approach for various. below is an example.

Legacy Way
Contract Way
If (X!=Null) Then DoJOB() Else throw Exception

It is not just syntactical improvement but it also support feature like conditional compilation, automatic document generation and intellisense support.

Getting Started
Learning curve for getting started is quite simple , all you need around 4-5 hours to get started. Below is the steps to get started.
  1. Install Prerequisite: Any version of visual studio 2010 except express.
  2. Install Code Contract Binaries
  3. Install Visual Studio Plug in (For Development)
  4. Watch the getting started video Getting Started with Code Contracts
  5. Read the documentation manual. It will take approximate 3-4 hours
  6. Happy Coding.
Further References

No comments:

Post a Comment