Hi Patrick,

On Tue, Feb 10, 2015 at 4:06 PM, Patrick Schaaf <p...@bof.de> wrote:

> Am 10.02.2015 07:25 schrieb "Yasuo Ohgaki" <yohg...@ohgaki.net>:
> >
> > https://wiki.php.net/rfc/dbc2
>
> First of all, thanks for your effort so far.
>
> Some questions, after reading the RFC, with no particular order:
>
> 1) Regarding invariants: those will be called for method calls on objects.
> What about static class methods? Could we have static class invariants
> (static require(.....))? Would these be called for both static and
> nonstatic method calls (nonstatic method calls can change static class
> state, too)
>
Static calls should not use $this->var, so invariant condition is ignored.
It should be in the RFC.

> 2) the pre- and postconditions could be useful for ordinary, non-OO
> functions, too, to check parameters, return, and global state invariants
>
I proposed __invariant() function, but some would not like to have it.
Since you've requested, we may consider again.

Rre/postconditions (require/return) can be used for non-OO functions.
It should be in the RFC. I'll add it in the RFC later.

> 3) I think that method preconditions are not sufficient. Pretty often,
> public methods first sanitize and validate their input parameters, and
> rightly so. In these cases, it would be useful to have the checking, in the
> same general framework, at an arbitrary point in the function body. In
> other words, assert (with an expression as the first argument, instead of a
> string....).
>
I might misunderstand you. Anyway,

assert( $var > 0 )

is allowed. So you can write usual PHP code. Even we can

assert( foo() ) // The same applies to require()/return()

is allowed. However, PHP does not allow in place closure call currently. We
cannot do

assert(function() { return $a > 0;} )

It's just ignored. This is the same as current assert().

> 4) regarding the error message second argument to the condition
> definitions, it would be useful to have these not only as plain
> (extrapolated) strings, but as full expressions-that-evaluate-to-string.
> That would permit hooking to arbitrary private logging and log formatting
> methods.
>
assert( $var > 0, '$var must be positive')

is allowed.
This should be in the RFC. require()/return() works just like assert().


> 5) and a bit off-topic, it would be useful to be able to declare (sic)
> whole methods to be nonproduction only: Methods that will only be used in
> pre/post/invariant condition expresions (or error formatters a la my point
> 4)
>

Do you mean enable DbC partially? Like

declare(dbc=1);

At the top of script?
I think it would not happen, but others may think it should.
Anyone?

Regards,

--
Yasuo Ohgaki
yohg...@ohgaki.net

Reply via email to