[GSOC] regular expressions beta is here

Don nospam at nospam.com
Wed Aug 10 21:58:51 PDT 2011


bearophile wrote:
> Contracts don't replace unittests, they complement each other.
> 
> 
>> They are nice but have little value over plain assert 
>> _unless_ we are talking about classes and _inheritance_, which isn't the 
>> case here.
> 
> It's easy to forget to test the output of a function, the "out" contracts help here. In structs the invariant helps you avoid forgetting to call manually a sanity test function every time you come in and out of a method.

You're conflating a couple of things here. Invariants are tremendously 
helpful for structs as well as classes.
"out" contracts seem to be almost useless, unless you have a theorem 
prover. The reason is, that they test nothing apart from the function 
they are attached to, and it's much better to do that with unittesting.
They have very little in common with 'in' contracts.

I think that EVERY struct and class in Phobos should have an invariant 
(except for something like Complex, where there are no invalid values).
But I don't think 'out' contracts would add much value at all.


More information about the Digitalmars-d mailing list