Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71721 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11838 invoked from network); 29 Jan 2014 11:10:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jan 2014 11:10:23 -0000 Authentication-Results: pb1.pair.com header.from=krebs.seb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.52 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 209.85.216.52 mail-qa0-f52.google.com Received: from [209.85.216.52] ([209.85.216.52:50586] helo=mail-qa0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 43/D2-28363-E91E8E25 for ; Wed, 29 Jan 2014 06:10:22 -0500 Received: by mail-qa0-f52.google.com with SMTP id j15so2172141qaq.39 for ; Wed, 29 Jan 2014 03:10:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=p6nCpcI7wrkL2qN8skXtF/1Ms33ahF48Oz1tfVsvp9w=; b=GESdXSGgpUyyM9SoT3ePJnQOReUQqasVCi4oKfsHvOKwmAVi+bVHd+fsRDHdg3fBPg m3v61tIBQzxMDWfKkRuZe3ECmcOqwPqlC21+RtNbLB210JOsnr+oixIjl3ChQPUpMPm0 pjWWaS5Vc+hGCYr6XonjBQlYt6Wr8WVgWu8PAw8YZYdefBgNeVhCe65Xrtza44mdyDan yzKedcpmidoWuKeDec6rp64H99pGWyb8NakejFMU+5aAO56pG3JLJAUbldLQarWVMT2A rr6aeQ2L/nRKyN03ELHGUfvHRteuZMAEg/+iJXUMIDiuZZWP6S6PlnUCRLZUZETPanHX CVDQ== X-Received: by 10.140.24.71 with SMTP id 65mr10310580qgq.12.1390993819577; Wed, 29 Jan 2014 03:10:19 -0800 (PST) MIME-Version: 1.0 Received: by 10.140.87.151 with HTTP; Wed, 29 Jan 2014 03:09:39 -0800 (PST) In-Reply-To: References: Date: Wed, 29 Jan 2014 12:09:39 +0100 Message-ID: To: Yasuo Ohgaki Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c13c5e804d3304f119fc32 Subject: Re: [PHP-DEV] DbC for PHP? From: krebs.seb@gmail.com (Sebastian Krebs) --001a11c13c5e804d3304f119fc32 Content-Type: text/plain; charset=ISO-8859-1 2014-01-29 Yasuo Ohgaki > Hi Sebastian, > > On Tue, Jan 28, 2014 at 5:36 PM, Sebastian Krebs wrote: > >> I'm wandering if we could have DbC (Design by Contract) for PHP 6. >>> http://en.wikipedia.org/wiki/Design_by_contract >>> >>> There is user land implementation already. >>> >>> https://gitorious.org/higher-order-php/php-contracts/source/5b0a53b9732f0e4dbe79345212c84c74526def3b >>> : >>> >>> It could be done with dbc mode INI switch as follows. >>> >>> When dbc=on, automatically includes >>> >>> include __dbc_ . __SCRIPT_NAME__; >>> >>> when a script is loaded. No error if there is not the script. >>> When function/method is called >>> >>> __dbc_pre_. __FUNCTION__() is called before calling function(). >>> __dbc_post_.___FUNCTION__() is called after function() call. >>> >>> No error if there is not the function. >>> >> >> Couldn't you achieve the same with assert()? >> > > Assert can be used for DbC and there are such implementations. > > Precondition is easy with assert(), but post condition is rather difficult > since > we need assert() before every 'return'. > Well .. Yeah. But that is difficult? > This could damage production code > (code executed on production environment) and contract readability. It > increases > chances of omitting post condition check by mistake. > This is possible with every implementation... > > Similar mistake may happen with this. > We may better to have option to warn non existent pre/post check. > > > Like Alexander explained, pure OO code can use DbC. It may be enough > for people who are interested in DbC. > > This is just an idea. It's simple, powerful and easy to adopt. Since there > is no DbC code in production code, it's fast while assert() need > compilation > overhead. It does not matter much with opcache, though. > No, at least not measurable. You can disable it. In that case it behaves like an empty function body. > > With this approach, user has to look up contract in other file. This is > disadvantage over other methods. > > I wander how many of us are interested in such feature. > > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > > -- github.com/KingCrunch --001a11c13c5e804d3304f119fc32--