Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are Code Contracts going to be supported in .NET Core going forwards? #6361

Closed
JamesKibirige opened this issue Jul 7, 2018 — with docs.microsoft.com · 15 comments
Closed

Comments

Copy link

@JamesKibirige JamesKibirige commented Jul 7, 2018 — with docs.microsoft.com

There is inconsistent information out there in regards to what is happening to Code Contracts in .NET Core going forwards. Currently, the functionality is not working out the box in .NET Core, I would like to know if Microsoft will be continuing support for Code Contracts in .NET Core?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@mairaw
Copy link
Contributor

@mairaw mairaw commented Aug 3, 2018

@terrajobst can you help with this question?

@terrajobst
Copy link
Member

@terrajobst terrajobst commented Aug 3, 2018

We have stopped investing in code contracts a while ago. We've added it to .NET Core 2.0 as part of our compatibility effort, but I wouldn't recommend new code using it.

FWIW, we've looked at many code bases that use them and it seems the overwhelming usage is about null handling. The replacement for this is under way with C# 8's nullable-reference types.

@mairaw
Copy link
Contributor

@mairaw mairaw commented Aug 4, 2018

Thank you for the update @terrajobst. With that, I'm closing this issue.

@mairaw mairaw closed this Aug 4, 2018
@kkm000
Copy link
Contributor

@kkm000 kkm000 commented Sep 23, 2018

@mairaw, I second that. Code Contracts are as dead as the dodo. The sooner this docs page is killed, the fewer people would be confused. A quick look at the issues shows that questions are still asked. We embraced them early, when it was an MSR project at quite early stages (it never graduated, really). There were two parts to it: a static code checking and a runtime code rewriter. The static checker, that proves all the pre- and postconditions and invariants, has a complexity exceeding that of your average theorem prover, and is rooted deeply in a quite complex algebra; it is Byzantine, to say the least, and nobody has ever touched it since @FrancescoLogozzo, the mastermind behind it, left MSR around 2014. This part really needs five years and a research team to keep it churning. The second component, the runtime code rewriter, is a hack that replaces contracts in compiler-generated code with runtime checks after compilation, and relies on certain peculiarities of the old, pre-Roslyn csc compiler's IL layout. As such, it breaks almost completely with Roslyn-produced code.

@SergeyTeplyakov and @mike-barnett did a great volunteer job trying to keep the project afloat at least for a while, and, AFAIK, are both still with Microsoft and probably can update you better than me. And oh boy, do not I wish I were wrong! :-(

@pkulikov
Copy link
Collaborator

@pkulikov pkulikov commented Sep 23, 2018

@kkm000 @mairaw

The sooner this docs page is killed...

What about archiving this page? That is, remove
https://docs.microsoft.com/en-us/dotnet/framework/debug-trace-profile/code-contracts

and redirect it to
https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/dd264808(v%3dvs.100)

which looks to be the same as the current doc page (except the update done by #7523)

@mike-barnett
Copy link

@mike-barnett mike-barnett commented Sep 26, 2018

Yes, I agree with @kkm000: the project is unlikely to be revivied. There is no one left to work on it. It would take a tremendous effort to maintain the static checker. Even the runtime checking support would need to be totally re-written.

Copy link

@jaypatrick jaypatrick commented Jan 10, 2019 — with docs.microsoft.com

While I realize from reading these comments that continuing to support this project would be quite expensive, it's unfortunate that this is what's happening. What's even more unfortunate is that nothing is coming along to replace it, b/c DbC is a very powerful coding and architecture paradigm. Is anything going to replace CC? Using it has been invaluable for me in the past.

@terrajobst
Copy link
Member

@terrajobst terrajobst commented Jan 10, 2019

We only have a replacement for non-null.

Copy link

@bkqc bkqc commented Jan 10, 2019 — with docs.microsoft.com

Another missing feature since CC is not conitnuing is the documentation benefit it gave (both in SandCastle and with the VS addon in C#). Please bring back something similar that would, using a single line, validate and generate doc (for min, max, returns, ...).

@jaypatrick
Copy link

@jaypatrick jaypatrick commented Jan 11, 2019

I started going through the code today, it is WAY above my mathematical skills. I can see why nobody wants to take this over within Microsoft now. Oh well, it was fun while it lasted. That being said, something like this wouldn't be too hard to implement with the new Roslyn API's...I hope Microsoft gives this another visit sometime in the future, because the value-add is tremendously beneficial, especially the ability to write all of your contracts to interfaces and have them inherited. It's a great way to centralize guards/etc.

Copy link

@mwwhited mwwhited commented Apr 2, 2019 — with docs.microsoft.com

Non-null is nothing compared to what code contracts was able to do. It's really a shame that Microsoft abandoned this project like many others.

Copy link

@clubforge clubforge commented Jul 23, 2019 — with docs.microsoft.com

@kkm000 @mairaw

The sooner this docs page is killed...

Well, I am still in the process of learning development in the .NET world, and I wish I had read these comments before spending an hour reading about Code Contracts. First I heard of it and thought it was quite interesting. Apparently, I am late to the show and wasted time reading this stuff. I suppose not a total loss, got some bits and pieces as a takeaway.

@TeddyAlbina
Copy link

@TeddyAlbina TeddyAlbina commented Aug 17, 2019

Code contract was a killer feature.

@mwwhited
Copy link

@mwwhited mwwhited commented Aug 17, 2019

Should be even easier with Roslyn... still a shame we didn’t get the compiler pipeline.

@SphtKr
Copy link

@SphtKr SphtKr commented Sep 17, 2019

I'll add to this--I started down the road like @clubforge and others... to have my hopes dashed by the conversation in this issue.

Making matters worse, the subject document had a typo corrected on 9/4/2018 and so the date at the top of the document shows this--making it look like this information is recent and relevant, which misled me.

I support the notion that this document should be archived as suggested above, or that some information should be added to it somewhere indicating that "We have stopped investing in code contracts a while ago... I wouldn't recommend new code using it."

Should that be opened as a separate issue, since the original issue title didn't really call for any specific action?

Of note, there is some discussion of supporting a construct like contracts directly in C#, beyond nullable reference types in C#8, here:

dotnet/csharplang#105

We can hope...but that's about it for the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.