Re: Design by Contract

From: Date: Thu, 05 Feb 2015 14:55:00 +0000
Subject: Re: Design by Contract
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-81932@lists.php.net to get a copy of this message
Hi Dmitry, Thank you for your time! On Thu, Feb 5, 2015 at 8:14 PM, Dmitry Stogov <dmitry@zend.com> wrote: > 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() > require(<input-assert-expression>) > ensure(<output-assert-expression>) > { > ... > } > > It would require only one new reserved word "ensure". > Less reserved word is better. > > The assert expressions may be checked or not depending on ini directive. > It should be also possible to prevent code generation for assertions (zero > cost asserts). It was already implemented for > https://wiki.php.net/rfc/expectations > > For inherited methods, only the self <input-assert-expression> should be > checked, and all parent <output-asser-expression>. This is borrowed from D > but not necessary to be repeated exactly. > > I think we shouldn't introduce "invariant" constraints for classes now. > May be later. > > Implementation is going to generate code for input constraint after all > RECV opcodes and before code for function body, and code for output > constraint before RETURN opcode (may be reusing implementation of > "finally"). > It seems fine to me overall. I have a few questions, but I think it's better to handle discussion as I promised. I'll ask later! Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net

« previous php.internals (#81932) next »