Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82029 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9922 invoked from network); 6 Feb 2015 09:34:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Feb 2015 09:34:33 -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.174 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.174 mail-vc0-f174.google.com Received: from [209.85.220.174] ([209.85.220.174:53758] helo=mail-vc0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/9C-45146-8AA84D45 for ; Fri, 06 Feb 2015 04:34:33 -0500 Received: by mail-vc0-f174.google.com with SMTP id le20so4651537vcb.5 for ; Fri, 06 Feb 2015 01:34:30 -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=U95QjFjwF0hvSzBIf9YncDdXEuBkWasPveeinCsHvPk=; b=arE7ptxBwFq5jowl2l20TIfGPefPqZWCJ3LgLjCa1DU2cPw4cZfF7DVLaqM3uAlMMB h8hiN0kkdkuzkIFKiTipnfWqYsF6VtLIfScHNf5LdQOFOrsQPS7Ei7h1clrX4S+r4RZc XRNRHpj3xnPiO/avfFSiP1BvDTgPk1pLfjk6jJZHA7FCUQdK1c8g+lzeyCxAwK1/VAq5 PLWBR9UTgVbynEDvsovF0x40dvd5eQ2foOjYdn9epLNqaD5juYASvexJUzZ5iNSiAbFl iwj7Qzz5yzXJ5/zJT3kvBwm3EH6dKMfB50fIHPWbhNlnh6ckFQbcNFNXdzU1cHFJOgQ0 Tamw== X-Gm-Message-State: ALoCoQns+jyWy3WNX/Y4Nk5PIFhz8w8N88Vo9ClalIRmmYde2KHwEfPzo0cQbDC964j+RtvBZ8YsNeIe8tOY+QwGcNQdsPxXk9ByoL6pUi+mCrZmjQPdEWEkjJlkj22EY/yPKLN0qZ08CdhPTWGzk0iK8dSfKFrHnA== MIME-Version: 1.0 X-Received: by 10.53.6.37 with SMTP id cr5mr1405965vdd.38.1423215269968; Fri, 06 Feb 2015 01:34:29 -0800 (PST) Received: by 10.52.74.73 with HTTP; Fri, 6 Feb 2015 01:34:29 -0800 (PST) In-Reply-To: References: <01d601d04146$6fbda4c0$4f38ee40$@tekwire.net> <020c01d0414b$2c3a1120$84ae3360$@tekwire.net> <023201d0415e$5731d800$05958800$@tekwire.net> Date: Fri, 6 Feb 2015 13:34:29 +0400 Message-ID: To: Yasuo Ohgaki Cc: =?UTF-8?Q?Fran=C3=A7ois_Laupretre?= , Pierre Joye , PHP internals Content-Type: multipart/alternative; boundary=001a1133e2c69b11ec050e6820be Subject: Re: [PHP-DEV] Design by Contract From: dmitry@zend.com (Dmitry Stogov) --001a1133e2c69b11ec050e6820be Content-Type: text/plain; charset=UTF-8 On Fri, Feb 6, 2015 at 2:01 AM, Yasuo Ohgaki wrote: > Hi Dmitry, > > On Fri, Feb 6, 2015 at 3:58 AM, Dmitry Stogov wrote: > >> I don't think we should chose "right" approach right now. >> It's better to collect few possible solutions e.g. statements, >> expressions, doc-comments, attributes... >> then describe their pros and cons to select the best one >> > > I agree. > > ensure($ret) {} > > is better than my original thought. > I don't object to restrict pre/post conditions to expressions. > > require(is_numeric($a) && $a >= 0, "some error message") > require(is_numerc($b) && $b >= 0, "another error message") > > this requires less lines and meaning is clear. For parsers other than PHP > > require { > assert(is_numeric($a) && $a >= 0, "some error message") > assert(is_numerc($b) && $b >= 0, "another error message") > } > > may be a little easy to parse. Even if it is, it's marginal. > > Allowing any PHP syntax would require other parsers complex parsing. > Those who would like to get pre/post conditions, it's time to think how > it looks like including reflection. Restricting pre/post conditions to > assert expressions may yield clean result. AST would be handy. > I think it should not be a big problem extending parser to support require/ensure syntax. AST is going to be really helpful :) Compilation is not going to be trivial but it's solvable. > Reflection is not too important, since pre/post conditions are for > development. It may be okay to reflect existence of pre/post conditions. > These conditions does not exists in production anyway. I'm not sure it's > worth to support reflection. Rather than reflection, user space AST browser > could be more useful. > > IMHO, E_WARNING is good enough. > If anyone would like to 'throw' exceptions, it's time to think, too. > We may relay on assert() behavior. Depending on some setting it may emit error or throw exception. Thanks. Dmtiry. > > These are my random thoughts. > > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > > --001a1133e2c69b11ec050e6820be--