Re: Design by Contract

From: Date: Sun, 08 Feb 2015 23:11:30 +0000
Subject: Re: Design by Contract
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi!

> Following our conversation, I tried to imagine how DbC should look like in
> PHP from user perspective. Finally, I was influenced by the semantic
> proposed in D, and syntax proposed for Java. So, these are my initial
> thoughts:
> 
> For php it may look like the following:
> 
> function foo()
>     requre(<input-assert-expression>)
>     ensure(<output-assert-expression>)
> {
>   ...
> }

Why not do it simpler?

function foo() {
// require
assert(<input-assert-expression>);
...
// ensure
assert(<output-assert-expression>);
}

I'm oversimplifying a bit, but in general, why we need more places to
have code in the function than the actual code of the function? It would
be harder to parse, to read, to maintain, to debug, to profile, etc. and
I'm not sure what exactly it provides that can't be done by plain
regular code inside the function.

If we're concerned about the costs of assert, we could make special
provision in the compiler for zero-cost asserts. It doesn't require
moving code out of the function.
-- 
Stas Malyshev
[email protected]


Thread (220 messages)