Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81902 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48317 invoked from network); 5 Feb 2015 11:47:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2015 11:47:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:53655] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/04-27691-06853D45 for ; Thu, 05 Feb 2015 06:47:45 -0500 Received: (qmail 5352 invoked from network); 5 Feb 2015 12:47:41 +0100 Received: from cm135-167.liwest.at (HELO RoLaptop) (81.10.135.167) by ns73.kreativmedia.ch with ESMTPSA (AES256-SHA encrypted, authenticated); 5 Feb 2015 12:47:41 +0100 To: "'Dmitry Stogov'" , "'Yasuo Ohgaki'" , "'PHP Internals'" References: In-Reply-To: Date: Thu, 5 Feb 2015 12:47:40 +0100 Message-ID: <006001d04139$8c1bd540$a4537fc0$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQGgxP9HPTh52uHWkGo6jLSeXRdtNJ1A534w Content-Language: de-ch Subject: AW: [PHP-DEV] Design by Contract From: php@tutteli.ch ("Robert Stoll") Hi Dimitry > -----Urspr=C3=BCngliche Nachricht----- > Von: Dmitry Stogov [mailto:dmitry@zend.com] > Gesendet: Donnerstag, 5. Februar 2015 12:14 > An: Yasuo Ohgaki; PHP Internals > Betreff: [PHP-DEV] Design by Contract >=20 > Hi Yasuo, >=20 > 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: >=20 > For php it may look like the following: >=20 > function foo() > requre() > ensure() > { > ... > } >=20 > It would require only one new reserved word "ensure". >=20 > 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 >=20 > For inherited methods, only the self should = be checked, and all parent expression>. This is borrowed from D but not necessary to be repeated = exactly. >=20 > I think we shouldn't introduce "invariant" constraints for classes = now. May be later. >=20 > 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"). >=20 > See: > http://dlang.org/contracts.html > http://jan.newmarch.name/java/contracts/paper-long.html >=20 > Thanks. Dmitry. I am not sure if this new syntactic sugar really improves readability. = What is the difference between the above and having something like? function foo($x, $y){ if(validateFoo($x, $y)){} =20 //do something $result =3D 'some value'; if(postValidateFoo($result){ return $ result; } } Actually putting everything in one function seems even worse from a = single responsibility point of view. But I suppose I am missing = something essential here. Cheers, Robert