Feature request: Optional, simplified syntax for simple contracts

deadalnix deadalnix at gmail.com
Mon Jun 17 22:27:52 PDT 2013


On Saturday, 15 June 2013 at 21:45:16 UTC, TommiT wrote:
> "Simple things should be simple, complex things should be 
> possible." -Alan Kay
>
> I'd like to simplify the syntax of function pre- and 
> post-conditions when the contract block consists of a single 
> assert statement. A special syntax for this special case would 
> omit all of the following:
> 1) the block's curly braces
> 2) the assert keyword
> 3) the semi-colon ending the assert statement
> 4) the body keyword (if and only if it follows right after the 
> block)
>
> So, instead of writing this:
>
> int func(int i)
> in
> {
>     assert(i < 5);
> }
> out(r)
> {
>     assert(r < 9);
> }
> body
> {
>     return i * 2;
> }
>
> ...you'd be able to write this:
>
> int func(int i)
> in (i < 5)
> out(r) (r < 9)
> {
>     return i * 2;
> }

I'd rather reserve this kind of syntax for static contract 
checking or something similar.


More information about the Digitalmars-d mailing list