After a spate of literal coding nightmares, I woke needing to commit these
thoughts to the list.  These may have been raised before, I can't remember,
these debate has been raging for so long.


THING 1: Hints are just is_* wrappers

function f(scalar $s, int $i) { }

effectively is sugar for:

function f($s, $i) {
    if (! is_scalar($s)) throw new \InvalidArgumentException();
    if (! is_int($i)) throw new \InvalidArgumentException();
}


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) {};


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'
}


I had to get these off my chest. Forgive me their implementation ignorance.
I am yet tired and uncaffeinated. To the void I commit their bodies...

bishop

Reply via email to