Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82220 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33763 invoked from network); 9 Feb 2015 04:25:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2015 04:25:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.48 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.192.48 mail-qg0-f48.google.com Received: from [209.85.192.48] ([209.85.192.48:54307] helo=mail-qg0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A2/15-26926-DB638D45 for ; Sun, 08 Feb 2015 23:25:33 -0500 Received: by mail-qg0-f48.google.com with SMTP id a108so19801613qge.7 for ; Sun, 08 Feb 2015 20:25:31 -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=6jG4N2u0Z0SXdygiUBE7G4s9CBmPta0MEEJE3cVk1YA=; b=ixmA8Z1bI3FbAM+sb//Y0rT2xE6zj4pENPJJniA8u02Yp/l7zrNIHNL+A5F4xOFXO8 2p4AqszxE2Nq2UdFy6nfuHKo7Dps4TJQ5IcB1yqglYx8ssKxjQGaGTOwq8LK7Zgi0yN9 7tSsct6VxBCD8PzrlmFA+9CSNt1RBqCAyKbxeoymU8SeZqkmp0HbK5zKN+JOU39tRHU0 5RyMoBh2eGcjgj15ZjEgEY0hgkl4ZOs2yjJjmnBkTiBCQJjUSh8UYUKGLV5kop/p3rTF AJmzIld0gIroIf17F/yvTPguxWUhl7F/4iS3QcbDkOhkB7E/tbxOSKmcRbtd5Pmrgej4 ZEag== X-Received: by 10.140.21.229 with SMTP id 92mr35384946qgl.33.1423455930969; Sun, 08 Feb 2015 20:25:30 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.229.28.72 with HTTP; Sun, 8 Feb 2015 20:24:50 -0800 (PST) In-Reply-To: References: <54D7ED22.3080001@gmail.com> Date: Mon, 9 Feb 2015 13:24:50 +0900 X-Google-Sender-Auth: SZHZoI7gTsYQSOtUTe2xKA9b7M4 Message-ID: To: "guilhermeblanco@gmail.com" , Joe Watkins Cc: Stanislav Malyshev , Dmitry Stogov , PHP Internals Content-Type: multipart/alternative; boundary=001a11c12f8c1e73fe050ea0294f Subject: Re: [PHP-DEV] Design by Contract From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c12f8c1e73fe050ea0294f Content-Type: text/plain; charset=UTF-8 Hi Guilherme, On Mon, Feb 9, 2015 at 11:58 AM, guilhermeblanco@gmail.com < guilhermeblanco@gmail.com> wrote: > Design by Contract could be used at the top of Annotation if (and only if) > it also had support for Interceptors. Since it could potentially be a > nightmare for PHP, I don't think it's time to propose something at the top > of another thing that is still far from being reality. > It would follow somehow a similar approach of what Symfony validators do: > http://symfony.com/doc/current/book/validation.html but it would be > called at possible 3 times: pre-execution, in-execution (using around and > bound to an external class) and post-execution. > However, I keep myself asking if this is a good idea. It obviously brings > a certain level of AOP to PHP, but I'd rather take a simplistic approach > such as the one suggested by Stas but with a few adjustments. > His approach is more inline to C and C++, but I like a more customizable > Java style assertion support > http://docs.oracle.com/javase/8/docs/technotes/guides/language/assert.html > Example: > > function foo($name) { > assert $name !== '': "Name must not be an empty value"; > } > > This would be similar to this: > > function foo($name) { > if ($name === null) { > throw new AssertionError("Name must not be an empty value"); > } > } > > Basically, new grammar to be supported would be something like this: > > assert_statement: > T_ASSERT expr ':' expr ';' > ; > > Where the first expr is a boolean expression and the second expr must > return a value (cannot be null). > > This would be a good start for PHP, even though Java does not recommend to > use this for argument's method check ( > http://docs.oracle.com/javase/8/docs/technotes/guides/language/assert.html#usage), > but I consider that since PHP is not a strict language, we do not have the > same privileges by automating this check form arguments itself. > > That is my personal suggestion for DbC, which does not fully align with > what it was proposed, but since you asked... here it is. > Thank you. Since assert is going to have zero performance penalty, Stas proposal would work. We have to think of how invariants should be. Joe, could you add "Proposal" section to the RFC. https://wiki.php.net/rfc/expectations Currently, it does not have "Proposal" section and it's harder to understand what the RFC is. Then, could you start vote? New assert is valuable regardless of DbC. The RFC will encourage users to use assert(), my little concern with Stas's proposal is misuse/abuse of assert(). Stas's proposal is simplest, but I'm not sure if we should go for it or not. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c12f8c1e73fe050ea0294f--