Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to Start with Code Contracts?

I saw an awesome demo of C# Code Contracts and I want to start implementing them into may code. I wish I had them in my code already. Where does one start?

I failed to take away any printed materials from the demo. Any suggested reading?

Any suggestions for a beginner with Code Contracts?

Thanks in advance for your help.

like image 766
Rodney Hickman Avatar asked Apr 18 '12 19:04

Rodney Hickman


2 Answers

I'd start with this Wiki which describes Design by Contract. Then dive into the documentation on MS' implementation. To actually work it into your code, I suppose you could start almost anywhere, but maybe start with areas that are least likely to have an impact. So maybe add some Contract.Requires to ctor arguments, if appropriate. When you're more comfortable, you can add them to interfaces, but be aware this may blow things up... but in a good way. Errors or warnings mean you're violating DbC, and likely the Liskov Substitution Principle.

like image 172
Andy Avatar answered Nov 20 '22 08:11

Andy


The user manual provided at the Code Contracts project page, gives a very good description of how to use and the possibilities of Code Contracts.

like image 37
Xharze Avatar answered Nov 20 '22 07:11

Xharze