Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81935 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9679 invoked from network); 5 Feb 2015 15:01:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2015 15:01:23 -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.170 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qc0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:63687] helo=mail-qc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 97/50-27691-2C583D45 for ; Thu, 05 Feb 2015 10:01:22 -0500 Received: by mail-qc0-f170.google.com with SMTP id p6so6740859qcv.1 for ; Thu, 05 Feb 2015 07:01:20 -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=sfdw6pUByMU5NlE1HOKC7V1Mz3aBwz/H/eDfz9xcJpE=; b=hAfvGCiHf/BqNyVFBGwJ9QBQLzl5IKv2z1qe1cp5sLbzaBXo6hv/XvNnwMzKh/AYZ3 rrDeiAEYR3OssKIsesllnTseu+D0Xad47wwBq/LpDHM4y4P1XtxoYU8v+pJmI0PJ5jRt GKOM68TlpUGRz74tl7DOs1nn/CsD7No1becUGyNLWXnYgk7Ntcoff4UivpehboyTR91J 3GNd/ApysfxPFDSN1LmRyKHLRNTVofQ4uiO0NngXB762b2SfG+Kn59V49HX0o0SHqVkE w0I1NTucBqUQtSR3JSdL34JvAt0ioc0P63gPSsoZajOKfhQ/eDzcEwGUgnWEt16/I1zS xjpQ== X-Received: by 10.140.42.22 with SMTP id b22mr8551609qga.43.1423148479995; Thu, 05 Feb 2015 07:01:19 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.229.28.72 with HTTP; Thu, 5 Feb 2015 07:00:39 -0800 (PST) In-Reply-To: <7740874.yAST26hVNS@rofl> References: <7740874.yAST26hVNS@rofl> Date: Fri, 6 Feb 2015 00:00:39 +0900 X-Google-Sender-Auth: uEkvyrHhN-t2vL-paLe2FLMBWnE Message-ID: To: Patrick Schaaf Cc: "internals@lists.php.net" , Dmitry Stogov Content-Type: multipart/alternative; boundary=001a11c12d769ce4e2050e5893aa Subject: Re: [PHP-DEV] Design by Contract From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c12d769ce4e2050e5893aa Content-Type: text/plain; charset=UTF-8 Hi Patrick, On Thu, Feb 5, 2015 at 9:13 PM, Patrick Schaaf wrote: > On Thursday 05 February 2015 15:14:04 Dmitry Stogov wrote: > > > > function foo() > > requre() > > ensure() > > { > > ... > > } > > > > It would require only one new reserved word "ensure". > > Regarding syntax.... This could be another place where the irrationally- > dreaded declare would make sense: > > function foo() { > declare(pre) { > if (whatever...) return false; > // arbitrary PHP code > } > declare(post=$resultvar) { > if ($resultvar == XXX) return true; > return false; > } > } > > This way, no new reserved words are needed at all, and the programmer can > give > a name to the "variable that holds the result" locally to avoid clashes > with > anything else in the function. > > I'm a bit undecided whether returning true/false there to give the verdict, > would be the best way. Maybe better would be another use for declare, > without > a block, to declare that the pre/postcondition failed - giving a nice > place to > put a suitable message, too. And again without introducing any extra > keywords: > > function foo() { > declare(post=$resultvar) { > if ($resultvar == XXX) declare(fail="My $resultvar looks fishy"); > } > } > The idea of "declare(post=$resultvar)" seems interesting, even though post=$resulvar looks wired. $resultvar is L value, but it's located as R value. There may be better syntax. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c12d769ce4e2050e5893aa--