Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which should I use, CodeContract or CuttingEdge.Conditions?

I researched the use of a condition framework to verify data instead of

if(cond) throw new SomeException();

SomeFramework.MakeSure(cond);

In the end my choice is to use either the CodeContract or CuttingEdge.Conditions frameworks.

I can not decide which framework to use. I can tell you that what I don't like about the 'CodeContract' framework is that you have to install the extra msi in order to use it and the options you need to choose; not that its bad, but it feels not natural. (And of course its still under MS research.)

What do you think?

like image 785
guyl Avatar asked Feb 19 '12 09:02

guyl


1 Answers

The CodeContracts framework is part of .NET 4. So you can write code against it without having to install anything, it's just that without the rewriter component the code contracts won't have any effect at runtime. I take this inclusion in the framework as a sign that Microsoft intends to integrate code contracts more in future.

According to the stats on the CuttingEdge.Conditions CodePlex page, it's only been downloaded 4,189 times. There are some nice things about the syntax, but unless there is something specifically supported by CuttingEdge.Conditions and not by CodeContracts, you might as well stick with the version that's part of .NET.

The key features of code contracts, as far as I am concerned, are as follows:

  1. You can set up code contracts on interfaces, to specify the expected behaviour of types implementing those interfaces.

  2. Code contracts are inherited.

I haven't tried CuttingEdge.Conditions, but it's not obvious that it supports these two features (whereas CodeContracts does).

like image 108
Matthew Strawbridge Avatar answered Oct 13 '22 19:10

Matthew Strawbridge