Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81952 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42850 invoked from network); 5 Feb 2015 17:55:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2015 17:55:11 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.171 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.216.171 mail-qc0-f171.google.com Received: from [209.85.216.171] ([209.85.216.171:64241] helo=mail-qc0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3E/E6-27691-E7EA3D45 for ; Thu, 05 Feb 2015 12:55:10 -0500 Received: by mail-qc0-f171.google.com with SMTP id s11so7644314qcv.2 for ; Thu, 05 Feb 2015 09:55:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=j/E0UtfygMRaa189UenSV8QWcpWSkdvT9klS4od7AE0=; b=sEbRw05EF07W8tBGMjT0bZF2mt2DuYa32bASYWFb674myoW0KPCOcVPFDNR/dEuUiy YZ2j5xM62iuec5hF6dG9L6PC7M1niRq92NI6pGck4dzSjWWpAIRgbyx+ond/Z/yvaIP5 nrxNLbvgHXwD9GHEtzAsH607MHEjqEaha+dpgwn27Z1n/GG9CF9Yc9f3DBT9YoY6OdLN otYzUiIqgyMRuOQ6tr/mGkOe9NxhOfIk7nTQ1pEvYrjGP9wq+QmmDCY6P0wknBzqwr0v vtrBaOpb68prCohdns34yvU3z2ZKk+HjlDHeOqdyhubFvG2C1kp2nSkjgdqxrppsUFyh pdOQ== X-Received: by 10.224.28.198 with SMTP id n6mr10557956qac.15.1423158907164; Thu, 05 Feb 2015 09:55:07 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.229.28.72 with HTTP; Thu, 5 Feb 2015 09:54:27 -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 02:54:27 +0900 X-Google-Sender-Auth: ueCrdoXB5dT_ms2PZHOikWGOK0o Message-ID: To: =?UTF-8?Q?Fran=C3=A7ois_Laupretre?= Cc: Pierre Joye , PHP internals , Dmitry Stogov Content-Type: multipart/alternative; boundary=001a11c2cc9a1ee0c5050e5b0157 Subject: Re: [PHP-DEV] Design by Contract From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c2cc9a1ee0c5050e5b0157 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Francois, On Fri, Feb 6, 2015 at 1:18 AM, Yasuo Ohgaki wrote: > > On Fri, Feb 6, 2015 at 1:11 AM, Fran=C3=A7ois Laupretre > wrote: > >> > De : yohgaki@gmail.com [mailto:yohgaki@gmail.com] De la part de Yasuo >> Ohgaki >> >> > We don't have to integrate DbC into phpdoc. phpdoc may have integratio= n >> of new DbC syntax. >> > I think it's helpful even if phpdoc copies post/pre condition as >> document. >> > >> > There are too many possibility for DbC syntax. >> > We are better to choose something in common among languages. >> >> No. The more I detail the concept, the more I read alternative proposals= , >> the more I consider extending phpdoc is the best solution. As I explain = in >> the RFC, both concepts are closely related, and that's the only solution >> I've seen so far that preserves BC. I could add that it proposes a solut= ion >> to issues not even detected nor discussed in alternative proposals, like >> the syntax for return value, separate check for arguments returned by re= f, >> built-in type checks, etc. Before we choose an alternative syntax, I thi= nk >> we should have good reasons, not 'Hey, that's how it's done in D !'. If >> there's a good reason to copy D or Eiffel syntax, let's adopt it, but I >> haven't read any good reason so far. And D is not so widely used so ther= e's >> no user habit. We can copy the concept without copying the syntax. >> >> I think we're going too fast here. Before giving up and switching to >> another syntax, can you give me a little time to present what I have in >> mind. I started writing it yesterday evening and it will be ready >> tomorrow morning (UTC). Then, we can make a decision. >> > > I didn't notice you have updated the RFC sorry. Sure, I'll read it and > respond. > https://wiki.php.net/rfc/dbc Thank you for your time. It's based on annotation approach. This kind of implementation requires a lot of work... I have more simpler approach in my mind based on current PHP language not to invent new language. I'll use syntax something similar to Dmitry proposed. Let me explain my original thought. Since we have reserved __functionname(), __some_functioname() should not have BC issues. ---------------- function foo($param) require ( // Compiled as __require_foo($param) // Any PHP code is allowed and works just like PHP function. // Abuse is possible. Users have freedom shoot their own foot. assert('is_string($param'); if (strlen($param) > 100) { echo "String is more than 100\n"; return FALSE; // return value is ignored. } ) ensure ( // Compiled as __ensure_foo($__return_value) // Same as require. Any PHP code assert('is_int($__return_value)'); // $__return_value is the return value assert($__return_value > 0); ) invariant ( // Check conditions always true. It may be __invariant_foo() // Question is should this have foo() scope? // Same as require/ensure. Any PHP code. // invariant() exists not to repeat require()/ensure() ) // Function body { // BODY } ---------------------- Zend engine has 2 execute() - execute() - Just execute foo() - execute_dev() - Call functions as follows __require_foo($param) __invariant() foo() __invariant() __ensure_foo($__return_value) With this approach, parser and compiler needs little modification and execute_dev() can handle additional functions while execute() only executes foo(). execute_dev() is simple because it just calls plain PHP functions if they exists. Is there is syntax error or assertion error. Error messages look like PHP Warning: assert(): asdfasdf failed in __require_foo() on line 2 This is simple yet useful/easy to use/powerful/flexible/fast. Any checks can be done with PHP syntax. I think assert() should be used usually, though. I thought to use require{} rather than require() because {} seemed natural for function. This is my thought. It's almost D. I don't know about AST much, so AST may be better/easier than having 2 execute(). Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c2cc9a1ee0c5050e5b0157--