this way we would able to use in constraints any statements.
The require/ensure syntax was limited to expressions (to limit users in
making side effects).

May be we may reuse delare() a bit differently.

function foo() {
    declare(pre=<input-constraint>)
    declare(post=<output-constraint>)
{

}

However. I like require/ensure more.

Thanks. Dmitry.

On Thu, Feb 5, 2015 at 3:13 PM, Patrick Schaaf <p...@bof.de> wrote:

> On Thursday 05 February 2015 15:14:04 Dmitry Stogov wrote:
> >
> > function foo()
> >     requre(<input-assert-expression>)
> >     ensure(<output-assert-expression>)
> > {
> >   ...
> > }
> >
> > It would require only one new reserved word "ensure".
>
> Regarding syntax.... This could be another place where the irrationally-
> dreaded declare would make sense:
>
> function foo() {
>     declare(pre) {
>       if (whatever...) return false;
>       // arbitrary PHP code
>     }
>     declare(post=$resultvar) {
>       if ($resultvar == XXX) return true;
>       return false;
>     }
> }
>
> This way, no new reserved words are needed at all, and the programmer can
> give
> a name to the "variable that holds the result" locally to avoid clashes
> with
> anything else in the function.
>
> I'm a bit undecided whether returning true/false there to give the verdict,
> would be the best way. Maybe better would be another use for declare,
> without
> a block, to declare that the pre/postcondition failed - giving a nice
> place to
> put a suitable message, too. And again without introducing any extra
> keywords:
>
> function foo() {
>     declare(post=$resultvar) {
>         if ($resultvar == XXX) declare(fail="My $resultvar looks fishy");
>     }
> }
>
> best regards
>   Patrick
>

Reply via email to