DIP 1009--Improve Contract Usability--Preliminary Review Round 1
MysticZach via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jun 21 01:15:34 PDT 2017
On Wednesday, 21 June 2017 at 04:16:22 UTC, Moritz Maxeiner wrote:
> What *I* need from a DIP that addresses DbC in D (to make it
> viable for me) is to make the simple case as easy as possible
> to read while not introducing language inconsistencies.
> With that in mind I am strongly in favor of the syntax H. S.
> Teoh already proposed:
>
> ---
> int myFunc(Args...)(Args args)
> if (Args.length > 2)
> in (args[0] != 0)
> in (args[1] > 1)
> out (result => result > 0);
>
> int myFunc(Args...)(Args args)
> if (Args.length > 2)
> in (args[0] != 0)
> in (args[1] > 1)
> out (result => result > 0) { ... }
> ---
>
> - in contracts take a parenthesis delimited bool expression
> - out contracts take a parenthesis delimited bool function
> literal.
`out` contracts would also have to account for the case where
they don't check the return value. This would confuse the grammar
a little in the case of function literals as boolean expressions.
A different possible grammar that wouldn't have this problem is:
OutStatement:
out ( IfCondition )
out ( Identifier ) ( IfCondition )
plus the existing ones:
OutStatement:
out BlockStatement
out ( Identifier ) BlockStatement
More information about the Digitalmars-d
mailing list