Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The guard clauses remind me of the compile-time verification done by Microsoft's Spec#[0] compiler, which included non-null types, checked exceptions and throws clauses, method contracts and object invariants. Some of those saw the light of day with C#, like the non-nulls, but whatever happened to the rest?

[0] http://www.rosemarymonahan.com/specsharp/papers/ECOOPTutoria...



Isn't that what evolved into System.Diagnostics.Contracts eventually?


Once I tried to use them, but forgot what was the issue... first of all - couldn't easily google on how to use it and then I think some legacy stuff was there that couldn't be used in .NET 4.7

> Code contracts aren't supported in .NET 5+ (including .NET Core versions). Consider using Nullable reference types instead.

https://docs.microsoft.com/en-us/dotnet/framework/debug-trac...

I didn't work any .NET Core version, but... could someone maybe provide some material/blogs/examples on how Contracts are to be used?

Statically verifiable arguments (where possible) are a dream that hasn't yet come true for me...


Yep, it has been effectively deprecated for a while, and now gone in new .NET versions. But when it was there, there was a static checker that you could run, and I thought that's where all the Spec# bits ended up in.

.NET 5+ basically doesn't have anything like contracts out of the box anymore.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: