What benefits does having code contracts available within the language/framework have? How does it compare to using unit tests or assertions instead?
closed as not constructive by MichaelT, Kilian Foth, thorsten müller, Bart van Ingen Schenau, Jalayn Apr 17 at 12:42
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.
At the moment, code contracts are not very useful compared to unit tests and similar mechanisms. The technology and the research is not quite there yet to enable fast and reliable compile-time static checking of contracts.
However, I expect this to change. I expect that by 2020 we will have static analysis tools that will successfully enforce code contracts and flag all violations with a compiler error. Eventually code contracts will become part of beginners’ introductions to programming.
However, personally I don’t think code contracts by themselves will replace unit tests. Maybe something else in conjunction with code contracts will, but not code contracts by themselves. Code contracts can only ensure certain properties about the code, but not semantic correctness. (Nor can unit tests, but together the two will catch more errors than one alone.)
|show 2 more comments|