April 09, 2009
Jarrett Billingsley Wrote:

> OK, then what about:
> 
> void foo()
> in { ... }
> out { ... }
> { ... }
> 
> the 'body' keyword is completely arbitrary.  There is no ambiguity here.
> 
> Also, I almost never use contracts because of their verbosity.  It's much shorter - and functionally equivalent - to just put asserts in the function body, some at the beginning and some in a scope(exit).

I like removing "body". But maybe we can make contracts a bit nicer by removing braces if the contract contains only one statement:

void foo()
in assert(something);
out assert(something_else);
{ ... }

would that be ambiguous to the compiler?

Tomek
April 09, 2009
Tomasz Sowiński wrote:
<snip>
> I like removing "body". But maybe we can make contracts a bit nicer by removing braces if the contract contains only one statement:
> 
> void foo()
> in assert(something);
> out assert(something_else);
> { ... }
> 
> would that be ambiguous to the compiler?

Probably not, but I'm not sure I like it at all.  Firstly, it reminds me of the old crocky C syntax for declaring parameter types.  Secondly, if we're going to allow contracts on abstract/interface functions, would you need to write two semicolons in a row with this syntax?

(Maybe there's no need for a semicolon in lieu of the body in such cases.  It's just what the compiler used to allow, though it never actually did anything with the contracts.)

Stewart.