Improve "Improve Contract Syntax" DIP 1009

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Nov 4 15:38:42 UTC 2017


On Saturday, November 04, 2017 15:27:39 Ola Fosheim Grøstad via Digitalmars-
d wrote:
> On Saturday, 4 November 2017 at 14:12:08 UTC, 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. Out contracts shouldn't
> > be testing specific values, 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.
>
> No, Jonathan is correct. The postcondition should be able to
> access values as they were stated in the precondition.

In principle, that would be nice, but in practice, it's not really feasible.
In the general case, there's no way to save the state of the parameter at
the beginning of the function call (you could with some types, but for many
types, you couldn't). IIRC, it's been discussed quite a bit in the past, and
there are just too many problems with it.

- Jonathan M Davis




More information about the Digitalmars-d mailing list