Lutger Blijdestijn wrote:
Don wrote:

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.

What about out contracts on interfaces in a library (where you use the library by implementing them).

That involves inheritance. But I don't think there are any cases in Phobos where that is currently applicable.


Reply via email to