Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82316 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32724 invoked from network); 9 Feb 2015 20:20:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2015 20:20:21 -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.52 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.192.52 mail-qg0-f52.google.com Received: from [209.85.192.52] ([209.85.192.52:51261] helo=mail-qg0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/07-25034-48619D45 for ; Mon, 09 Feb 2015 15:20:21 -0500 Received: by mail-qg0-f52.google.com with SMTP id h3so19543439qgf.11 for ; Mon, 09 Feb 2015 12:20:18 -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=kwdtbsIQ7DY3EuB15KZEZ/gXUATVSpcrt/Flv/rEJAY=; b=0TPns5V/OVY+Wyzjwp6vt6+8V7vUI2X9LjlZEkg2z4yoSA1QZMtSiFQFuWgpT6Qn/a ZEI4fsUDKvGNX/mvfAOmkt+fVyD60UQcwnW5xCv30lFV6B1BxaYArj4pPlZOAPqyNZtF aI9wekdhdAFe1g9sHJiZMGb9VE8qWuqlPkrNamC6rx6Gz+ZXHLmd3ie/vkp5hliWmX0X P58ySATUze9LeZzyYrZXmn0M1BECsvw927gHBqxyXS7nNWl66gLHOa+OnuEEfwqOzH1q litWf+kBiMmvtLRZFJBLI88TujZ+58NGjv69A2DhEgndvlGTT33WuKkZnRz0rkd8Fyty wIkg== X-Received: by 10.224.119.199 with SMTP id a7mr29201571qar.68.1423513218578; Mon, 09 Feb 2015 12:20:18 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.229.28.72 with HTTP; Mon, 9 Feb 2015 12:19:37 -0800 (PST) In-Reply-To: References: <54D7ED22.3080001@gmail.com> Date: Tue, 10 Feb 2015 05:19:37 +0900 X-Google-Sender-Auth: SD_DMRx7w3u2MgQLWse5JME1KSE Message-ID: To: Dmitry Stogov Cc: Joe Watkins , Stanislav Malyshev , PHP Internals Content-Type: multipart/alternative; boundary=001a11c2f9b4ba0189050ead7f47 Subject: Re: [PHP-DEV] Design by Contract From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c2f9b4ba0189050ead7f47 Content-Type: text/plain; charset=UTF-8 Hi Dmitry and Joe, On Mon, Feb 9, 2015 at 8:27 PM, Dmitry Stogov wrote: > yes. this may work. > probably better to put it after extends and implements. > > > Dmitry. > > On Mon, Feb 9, 2015 at 2:19 PM, Joe Watkins wrote: > >> Could this be described as a requirement of the class ? >> >> class Mine >> require(invariant-expr) >> extends Something >> implements Someface { >> >> public function method($param) : return >> require(input-expr), >> return(output-expr) { >> >> } >> } >> >> To avoid invariant keyword maybe. >> > This would work. If users have adopted DbC in some way, 'invariant' may be used already. I see two issues. Interface works, but most classes are class without interfaces. Then users have to repeat require()/return() many times to check class state or have to use interface for DbC. Since compiler does not know a method() is for DbC invariant, it will be compiled and exists in production execution. Use of interface: - no additional keyword (pros) - requires interface for DbC, most classes does not require interface (cons) - if interface is not used, user has to repeat invariant conditions over and over (cons) - requires to define method that should not exist in production (cons) New keyword: - does not require interface for efficient definition (pros). - new keyword (cons) It seems we are better to choose proper keyword for 'invariant'. 'invariant' is not common, so 'invariant' may be good enough choice. Does anyone use 'invariant' as function/method/class/constant names? If there is better name, suggestion is appreciated. On place closure call like javascript is not supported in PHP, but function works with assert. PHP Warning: assert(): Assertion failed in - on line 3 This wouldn't be changed for require()/return()/invariant()? We need a switch to change development/production. I'll use "dbc=On/Off" for now. If you have any better idea, please let me know. (dbc will be INI_SYSTEM) For CLI, there will be no command line switch for dbc. It executes script production mode by default. If user needs development mode php -d dbc=1 script.php should be used. And finally, are we going to allow custom assertion error message? e.g. require($a > 0, 'Parameter $a must be positive number'); Since this contract is definition like "implements"/"extends", we may not allow custom error message. I'll write the RFC not to allow custom error messages unless you dislike it. I think we have enough consensus/information to start writing the RFC. If I have any concern, I'll ask here. Regards, P.S. If anyone finds issues with DbC as class definition, please let me know. -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c2f9b4ba0189050ead7f47--