Hi Bishop,

On Wed, Feb 18, 2015 at 9:18 PM, Bishop Bettini <bis...@php.net> wrote:

> THING 2: Hints are truthy callables
>
> function my_mixed($m) {
>     return (null === $m || is_string($m));
> }
> function f(is_scalar $s, is_int $i, my_mixed $m) {};
>
>
This is interesting idea. I'm sure it will be much slower than type hints
as it
calls functions, but it's still interesting idea. i.e. Cost of calling
functions are
not cheap. Inline optimization will help, but it increases byte code size.

Type hint implementation is a lot simpler than this.

THING 3: Pre- and post- blocks to define contracts, establish formal join
> points, with or without hints from above
>
> function f($s, $i, $m)
> before {
>     if (! is_scalar($s)) throw new \InvalidArgumentException;
> },
> inside {
>     $fp = fopen($s, 'r');
>     return [ $i, $m ];
> },
> after ($retval) {
>     assert(is_array($retval) && 2 === count($retval));
> },
> finally ($retval) {
>     fclose($fp);
>     if ($retval instanceof \Exception) {
>         // I got here by an unhandled exception
>     }
> }
>
> weave('before', 'f', function ($s, $i, $m) {
>     syslog(LOG_DEBUG, __POINTCUT__); // is 'f'
> }
>

Although it has similarities, AOP and DbC cannot share blocks/etc. AOP is
for production codes, DbC is _not_ for production codes, but only for
development
and testing. These are 2 distinct features.

Regards,

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

Reply via email to