On 04.11.2017 10:12, Adam D. Ruppe wrote:
On Saturday, 4 November 2017 at 13:59:39 UTC, Jonathan M Davis wrote:
I'm very much of the opinion that proper unit tests pretty much eliminate the need for out contracts.

I think that sqrt example is just bad.

It is indeed bad, because it is buggy.
(The out contract may overflow.)

Out contracts shouldn't be testing specific values,

It's not testing specific values. It is testing for input-dependent properties of the output (which in this case happen to pinpoint the output exactly for each input).

but rather ranges or nullness or other such things that arguably should be part of the return type, but just don't fit in the type system for whatever reason.

I don't see how that is in contrast to the given example. Clearly, the conditions that it is testing for should have been represented in the type system. Then the example would not compile. Also, one would not be able to complain about runtime overhead.

Reply via email to