3 ms·
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
by chem83 5y ago
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/ECOOPTutorial.pdf http://www.rosemarymonahan.com/specsharp/papers/ECOOPTutoria...
- int_19h 5y agoIsn't that what evolved into System.Diagnostics.Contracts eventually?
- jve 5y agoOnce 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-trace-profile/code-contracts 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...
- int_19h 5y agoYep, 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.