My body is ugly [Re: Contextualizing keywords]

Denis Koroskin 2korden at gmail.com
Mon Aug 3 05:34:18 PDT 2009


On Mon, 03 Aug 2009 16:22:40 +0400, Michiel Helvensteijn  
<m.helvensteijn.remove at gmail.com> wrote:

> Denis Koroskin wrote:
>
>>> Then I assume you still want to restrict the precondition to being the
>>> first element in the body? Because putting it in there suggests that it
>>> may appear anywhere a statement can.
>>
>> Why not?
>
> Because a function precondition indicates the set of admissible states
> before execution of a function. Emphasis on *before* and *function*.
>

Allowing them anywhere inside a function body will only improve the  
feature.

BTW, it is already allowed, just use 'debug' instead of 'in':

Suggested way:

> int foo(int a) {
>    in {
>       assert(a>2);
>    }
>
>    return a-1;
> }

My way:

int foo(int a) {
    debug {
       assert(a>2);
    }
    return a-1;
}

TBH, I'd just drop the whole DBC feature from a language, it creates more  
problems than solves.



More information about the Digitalmars-d mailing list