Re: DbC for PHP?

From: Date: Wed, 29 Jan 2014 22:13:28 +0000
Subject: Re: DbC for PHP?
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 28/01/2014 11:05, Alexander Lisachenko wrote:
Here is my one-minute implementation with Go! AOP framework. [...]
class Test {
     /**
      * @Contract("strlen($foo) > 6")
      */
     public function bar($foo)
     {
         echo $foo;
     }
}
So, dozens of lines of boilerplate, Reflection, and other obscure features (including, presumably, a userland implementation of annotations) and the end result is ... an assertion. The pre-condition is not being added as an aspect, it's hard-coded right there next to the function, doing exactly the same thing as adding this single line at the top of the function: assert('strlen($foo) > 6'); Post-conditions are a little trickier: they require a single-point-of-return (something which has its advocates anyway, and could easily be enforced as a project coding standard) and potentially introduce an intermediate variable that could otherwise be skipped. But this seems like a lot of overhead to work around that. Now, I realise that this was a simple example, but I would be interested to see what such an approach could actually offer in return for its complexity. Regards, -- Rowan Collins [IMSoP]

Thread (8 messages)

« previous php.internals (#71759) next »