4 ms·
Code Contracts seem rather silly. C#/VB is statically typed, no? Method contracts should be implicit in the method declaration, then. Granted, this gives you m
by warfangle 17y ago
Code Contracts seem rather silly. C#/VB is statically typed, no? Method contracts should be implicit in the method declaration, then.
Granted, this gives you more control over what literal values may be passed to a method. But isn't that (part of) what exceptions are for? What additional value do these add?
- lincolnq 17y agoIt looks like a fairly powerful static analysis framework, well beyond what the C# type system can prove. Not sure what exactly it can do, but the static checker dialog box allows you to enable: Implicit Non-Null Obligations Implicit Arithmetic Obligations Implicit Array Bounds Obligations Redundant Assumptions If it can do a good job of checking these statically, I'm impressed!
- viggity 17y agoThe big advantage to code contracts is that they prevent null reference exceptions at compile time. Catching potential problems at compile time via static checking is preferable than throwing an exception at runtime. Your code is more resilient to bad data. Having a formal checking mechanisms like code contracts also helps tools like Pex generate better sets of test inputs for automated unit testing.