Re: Design by Contract

From: Date: Wed, 11 Feb 2015 07:58:56 +0000
Subject: Re: Design by Contract
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14  Groups: php.internals 
Request: Send a blank email to internals+get-82446@lists.php.net to get a copy of this message
Hi! > 1) contracts in doc-commetns https://wiki.php.net/rfc/dbc > > /** > * @requires ($a >= 0) > */ > function foo($a) { > } We've spent several years rejecting annotations because no information can be in comments, not even a little bit, not even a tiny. Now we'd have full-blown running code in comments? How would this code be debugged/profiled/interpreted by tools? Writing PHP parser is not easy right now, but this would turn it into nightmare (what if you have a comment inside @requires? etc.) > 2) contracts as part of the language > https://wiki.php.net/rfc/dbc2 > > function foo($a) > require($a >= 0) > { > } This is a step better but still we have the similar issues with readability, to which reuse of 'require' is added. > 3) contracts in annotations > > <<requires($a >= 0)>> > function foo($a) { > } That one actually looks better to me, but: I'm not sure how annotation syntax is supposed to support expressions or closures, yet more - how it is supposed to share the scope with the function. I.e., if you define annotation class/method/function/data structure/whatever it is, what it is supposed to receive? Is it some special form of annotation for this purpose only (meh)? Oh, and <<>> syntax is *ugly* ;) -- Stas Malyshev smalyshev@gmail.com

« previous php.internals (#82446) next »