Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81904 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51597 invoked from network); 5 Feb 2015 11:56:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2015 11:56:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.181 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.181 mail-vc0-f181.google.com Received: from [209.85.220.181] ([209.85.220.181:54274] helo=mail-vc0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 21/B4-27691-47A53D45 for ; Thu, 05 Feb 2015 06:56:36 -0500 Received: by mail-vc0-f181.google.com with SMTP id id10so2496804vcb.12 for ; Thu, 05 Feb 2015 03:56:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=Qf3Vi32oxPpnbOtKhyPGW72pFagTyxzeN7F7BdQFA+k=; b=hhqpceU2UdYDNStkc0QPZU2fdzct/iMwPKrqrWW4of7n8p53HFQwEWjnLZXuZs0x2P QV3nC7ilF2siksqV7RdjnxZNCLACxUoEOJl+lru4s7NACzTW/FA2dtvfAkIJnBH9vwOP c9s+6rD/yJbMi7wekj6kahWjXi68YuQiTG2N5L0mF6gzZ6TeOxVOAnNMBj55OPVnH/Vp LfDCyDkIg3Mxpb5Sk+3hxOc+buM2W52zzjNn3w/bwrkFSOuk2Y6Gz2LyLhLOlZLlcrx0 zrmnKy2LH206v8PX61IVOno5CU8noElTikVr8/P9eOsteJIiZFbWZ4F7yD5nlkvc/ccH 60Ww== X-Gm-Message-State: ALoCoQmpfeWSu49Kmbi5njrSFa0qJa8NCbEFhIFcmpZn7Zjl/4tx/e0dHnzkqweP3QlnYs15iQ2PVfOOYHe0QJ3JwJXRHPzA7TOiwn60TkPZ9z2ccD5v6ap2FFBq1KCzuLHcREs8EDvrrqqpxg/bz+34l+7/RIP3vw== MIME-Version: 1.0 X-Received: by 10.220.185.193 with SMTP id cp1mr1469210vcb.80.1423137393038; Thu, 05 Feb 2015 03:56:33 -0800 (PST) Received: by 10.52.74.73 with HTTP; Thu, 5 Feb 2015 03:56:32 -0800 (PST) In-Reply-To: <006001d04139$8c1bd540$a4537fc0$@tutteli.ch> References: <006001d04139$8c1bd540$a4537fc0$@tutteli.ch> Date: Thu, 5 Feb 2015 15:56:32 +0400 Message-ID: To: Robert Stoll Cc: Yasuo Ohgaki , PHP Internals Content-Type: multipart/alternative; boundary=089e01538610c7a6c4050e55fe3f Subject: Re: [PHP-DEV] Design by Contract From: dmitry@zend.com (Dmitry Stogov) --089e01538610c7a6c4050e55fe3f Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Robert, This is about "declarative" vs "imperative" programming. Also constraints may be enabled for debugging and completely disabled for production. I'm not the inventor of this approach, I just started to think about it myself :) You opinion makes sense as well. PHP doesn't have to support all the possible features. Thanks. Dmitry. On Thu, Feb 5, 2015 at 2:47 PM, Robert Stoll wrote: > 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 > > > > Hi Yasuo, > > > > 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: > > > > For php it may look like the following: > > > > function foo() > > requre() > > ensure() > > { > > ... > > } > > > > It would require only one new reserved word "ensure". > > > > 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 > > > > For inherited methods, only the self should b= e > checked, and all parent > expression>. This is borrowed from D but not necessary to be repeated > exactly. > > > > I think we shouldn't introduce "invariant" constraints for classes now. > May be later. > > > > 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"). > > > > See: > > http://dlang.org/contracts.html > > http://jan.newmarch.name/java/contracts/paper-long.html > > > > 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)){} > > //do something > $result =3D 'some value'; > > if(postValidateFoo($result){ > return $ result; > } > } > > Actually putting everything in one function seems even worse from a singl= e > responsibility point of view. But I suppose I am missing something > essential here. > > Cheers, > Robert > > > --089e01538610c7a6c4050e55fe3f--