4

Since the introduction of Contracts to .NET 4.0, I am wondering if Microsoft propagated this to all of their classes like in the BCL?

If not, then why? This kind of feature only makes sense if it's supported in the standard library by default, right?

Harsh Baid
  • 7,199
  • 5
  • 48
  • 92
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
  • You can see that Microsoft has made a good effort to do so by looking at the source, which is available in the public symbols. I doubt that have done this very extensively, if only because it would be cost prohibitive. – vcsjones Mar 07 '11 at 18:32
  • Sorry I am not sure what you mean. You mean Microsoft looked at the source code and did some of it "automatically" by some sort of batch tool? – Joan Venge Mar 07 '11 at 18:34

2 Answers2

2

Not all of the BCL.

Consider that Code Contracts is not fully built into the IDE and the language just yet; it's a separate download. Undoubtedly when it has achieved greater developer penetration, increased integration with the IDE and full annotation of the BCL we 'll see it offered out of the box.

Jon
  • 428,835
  • 81
  • 738
  • 806
  • So it will change in the future? So contracts doesn't come out of the box when you install VS 2010? – Joan Venge Mar 07 '11 at 18:33
  • 1
    @Joan: The [`Contract` class](http://goo.gl/uNEmd) and [other classes](http://goo.gl/r3AGi), which are used to declare the contracts are included in the BCL of .NET 4.0. But the Binary Rewriter (ccrewrite.exe) that actually inserts the contracts into your assembly, Static Checker (cccheck.exe) that verifies the correctness and compliance to the contracts (Premium edition and upwards) and the project property page that allows you to configure Code Contracts are all in a [separate add-on](http://goo.gl/2a7b). And there's also the [editor extensions add-on](http://goo.gl/ZGq4I). – Allon Guralnek Mar 07 '11 at 18:59
2

No Code Contracts have not been added to all of the BCL. Many of the most common classes have added the annotation but the whole of the BCL has not.

The primary reason here is time. The BCL is huge and adding correct Contracts to all of the BCL is a massive undertaking. And the result, at this time, only benefits a small subset of the .Net user base. If Contracts grow in popularity then I'm sure their usage within the BCL will likewise grow (yes I realize not doing one makes the other less likely)

This problem is mitigated though by the ability for users to declare custom Contract assemblies. This allows them to post-annotate types which were missed and get to a point where their code base is clean from a Contracts point of view.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • Thanks Jared, so you mean you can add contracts like extension contracts, after the fact and without the source? – Joan Venge Mar 07 '11 at 20:05
  • Also I thought the contracts were a default supported feature of .NET, just like anything else. Why isn't it made standard? What I mean is, it seems like this feature is optional like even though it's a good practice you don't need to use it. Hard to describe since it's a framework feature. – Joan Venge Mar 07 '11 at 20:07
  • 1
    @Joan it is a standard feature it's just the work required to get it fully into the code base is daunting. It essentially amounts to changing every single place argument checking is performed. – JaredPar Mar 07 '11 at 20:23
  • Thanks Jared, so are you guys gonna fully update it in the future? I know you said in your post, it depends on the usage grow, but how will you measure it, right and considering static analysis is not available in visual studio pro will negatively affect this severely. – Joan Venge Mar 07 '11 at 20:34
  • 1
    @Joan I don't work on the team responsible for the annotations but my **guess** is that you won't see a lot more updates anytime soon. – JaredPar Mar 07 '11 at 22:13