DIP 1009--Improve Contract Usability--Preliminary Review Round 1

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 23 09:21:28 PDT 2017


On Fri, Jun 23, 2017 at 09:06:59AM +0000, Solomon E via Digitalmars-d wrote:
[...]
> T foo(T)(T x, T y)
>     in (x > 0, y > 0)
>     out (r; r > 0)
> {
>     return x % y + 1;
> }

Hmm, I like this syntax for out-contracts!  It borrows from existing
foreach syntax, so it has some precedence, whereas the previous proposal
of `out(...)(...)` looks uglier and also looks deceptively like a
template function declaration.

`out (r; r > 0)` gets my vote.


OTOH, I don't like the comma in the in-contract.  Let's just keep it as
either separate clauses:

	in (x > 0)
	in (y > 0)

or just use a boolean operator:

	in (x > 0 && y > 0)


T

-- 
Two wrongs don't make a right; but three rights do make a left...


More information about the Digitalmars-d mailing list