Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82257 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6041 invoked from network); 9 Feb 2015 10:35:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2015 10:35:09 -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.192.45 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.192.45 mail-qg0-f45.google.com Received: from [209.85.192.45] ([209.85.192.45:65498] helo=mail-qg0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DB/EA-50460-B5D88D45 for ; Mon, 09 Feb 2015 05:35:08 -0500 Received: by mail-qg0-f45.google.com with SMTP id h3so14829912qgf.4 for ; Mon, 09 Feb 2015 02:35:05 -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=OvL+NsaaKysknVBHfOgHrpreXzbOPcP5i+G+fELsWFg=; b=hvgpNvF4QmYeUn7CXyS4+PeBXijKd5jIRYDmOKqSlAl1LU2u08P5ZzJknrpruGntJ4 DcDIwlBXBEasS7OQC3kMhtZRCKyU1q2o+3jRcT/rO+aCv+My8ZfX4L+weX79EtDvTkcs CozBEOisSOSyBa0qHxYu7ttnR2Ko9tzOznqYBDWc4KAK/GemyZHa5StihDsftPXy4ifR KyHaSn0lQknv9i7e5LQp4daXe1BlLEQKt7gMusehdhpyPN7pSJQMLqCyhpsK+wOjzRUT 0x1Pr/p17Z1iGgq8nM2QqwVhDWDm4IHERFODqD2N5AllfV5Jg7Dtt18/37bReCefnqDY Rwnw== X-Received: by 10.224.38.70 with SMTP id a6mr11228219qae.15.1423478105723; Mon, 09 Feb 2015 02:35:05 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.229.28.72 with HTTP; Mon, 9 Feb 2015 02:34:25 -0800 (PST) In-Reply-To: References: <54D7ED22.3080001@gmail.com> Date: Mon, 9 Feb 2015 19:34:25 +0900 X-Google-Sender-Auth: hlBk8kEqcpx63vZ3ozh8BGBYllQ Message-ID: To: Dmitry Stogov Cc: Joe Watkins , Stanislav Malyshev , PHP Internals Content-Type: multipart/alternative; boundary=001a11c2d274d65b61050ea552a0 Subject: Re: [PHP-DEV] Design by Contract From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c2d274d65b61050ea552a0 Content-Type: text/plain; charset=UTF-8 Hi Dmitry and Joe, On Mon, Feb 9, 2015 at 6:01 PM, Dmitry Stogov wrote: > Usage of "return" is a good idea. > The more heads the better result :) > Less additional reserved word :) So I'll use "require" and "return" for D like RFC. We haven't talk much about invariants. I'll write my idea. Current RFC is large enough already, I'll prepare new one. We may decide what to do with 2 RFCs. We have choices for with block or without block. I prefer with block version, since assert expression could be messy. With block, IDE may do it's jobs. i.e. Hide blocks. ============================================== Function/Method [With block] function foo() require { assert(assert-expr, 'msg'); assert(assert-expr, 'msg'); assert(assert-expr, 'msg'); } return { assert(assert-expr, 'msg'); assert(assert-expr, 'msg'); assert(assert-expr, 'msg'); } invariant { assert(assert-expr, 'msg'); assert(assert-expr, 'msg'); assert(assert-expr, 'msg'); } { // body } _OR_ [Without block] function foo() { require(assert-expr, 'msg'); require(assert-expr, 'msg'); require(assert-expr, 'msg'); invariant(assert-expr, 'msg'); invariant(assert-expr, 'msg'); invariant(assert-expr, 'msg'); return(assert-expr, 'msg'); return(assert-expr, 'msg'); return(assert-expr, 'msg'); // function body } Currently, following code wouldn't work (PHP 7.0.0-dev) ---------- assert(function() {return FALSE;}, 'AAAAA'); ---------- For block version, which do you prefer, allow any PHP syntax or assert only? People may use anonymous function to do fancy jobs anyway if it's supported. No block version only accepts EXPR obviously, but anonymous function may be used with this as well. ============================================== Class invariants [With block] class Foo { __invariants() { assert(assert-expr, 'msg'); assert(assert-expr, 'msg'); assert(assert-expr, 'msg'); } } _OR_ [Without block] class Foo { __construct() { invariant(assert-expr, 'msg'); // Only allow in __construct()? Allowing invariant. invariant(assert-expr, 'msg'); invariant(assert-expr, 'msg'); } } ============================================== Global invariant I'm not sure if we should have function __invariants() { assert(assert-expr, 'msg'); assert(assert-expr, 'msg'); assert(assert-expr, 'msg'); } _OR_ invariant { assert(assert-expr, 'msg'); assert(assert-expr, 'msg'); assert(assert-expr, 'msg'); } to assert global vars, whole app state, etc. It may be useful for unit tests as well as app development. I'll start working after I get comment from you. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c2d274d65b61050ea552a0--