Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71719 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3145 invoked from network); 29 Jan 2014 08:48:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jan 2014 08:48:21 -0000 Authentication-Results: pb1.pair.com smtp.mail=ivan.enderlin@hoa-project.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=ivan.enderlin@hoa-project.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain hoa-project.net from 95.130.10.56 cause and error) X-PHP-List-Original-Sender: ivan.enderlin@hoa-project.net X-Host-Fingerprint: 95.130.10.56 host1.ip6-networks.net Received: from [95.130.10.56] ([95.130.10.56:41086] helo=host1.ip6-networks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 10/C1-28363-050C8E25 for ; Wed, 29 Jan 2014 03:48:17 -0500 Received: from Hwhost2.local (184-175.106-92.cust.bluewin.ch [92.106.175.184]) by host1.ip6-networks.net (Postfix) with ESMTPSA id 9D4506090A for ; Wed, 29 Jan 2014 09:48:13 +0100 (CET) Message-ID: <52E8C04E.1090609@hoa-project.net> Date: Wed, 29 Jan 2014 09:48:14 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:28.0) Gecko/20100101 Thunderbird/28.0a2 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] DbC for PHP? From: ivan.enderlin@hoa-project.net ("Ivan Enderlin @ Hoa") On 28/01/2014 08:05, Yasuo Ohgaki wrote: > Hi all, Hello :-), > 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/5b0a53b9732= f0e4dbe79345212c84c74526def3b: > > It could be done with dbc mode INI switch as follows. > > When dbc=3Don, 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. What kind of errord would you like to print? =E2=80=9CThe precondition ha= s=20 failed=E2=80=9D, ok but why? With what data? > Class methods would be more complex, but basic idea is the same. > Issue would be what we should do with $this with class methods. > > Automatic namespace might be nice to have for both function and class. > > When dbc=3Doff, these would be skipped at all. > > It does not sacrifice performance at all for production while it could = catch > various errors during development. It could do more complex assertion > than assert() So the pre- and postconditions must be predicates, i.e. computing a boole= an. > and it could check post condition that is difficult to achieve > by assert(). User could have their own strong type safety as long as th= ey > have strict input validation. It could be used as complement of annotat= ion. > > Just an idea. > Any comments? What about invariants which is the third part of DbC? Did you heard about Praspel [1]. Praspel is a BISL (Behavioral Interface = Specification Language), i.e. a specification language for=20 contract-based testing I develop in my PhD thesis (in INRIA=20 laboratories). You will find some materials here [2]. I recommend you to = start by the presentations/keynotes. The idea is to allow the user to=20 write contracts (precondition, postcondition, exceptional postcondition, = invariant, behavior etc.), and we exploit them in order to generate=20 (unit) tests automatically. I'm reaching the end of my PhD and I'm currently writing the=20 documentation and finalizing the tools. Today, we are able to: (1) generate very different kinds of data (strings with regexs or=20 grammars thanks to grammar-based testing algorithms [3, 4], arrays=20 thanks to an array-solver [5] etc.) (2) verify a contract with a Runtime Assertion Checker (please, see = articles or directly the code [6]) (3) automatically generate (unit) tests that are executable with=20 atoum's API [7, 8] We are preparing videos and documentations in order to promote it up to=20 June. I suggest to read the presentations, you will get an overview of=20 all the work. I think DbC must stay annotations, so in comments of the code. If=20 contracts would be part of the PHP grammar, it would be disappointed for = everyone because there is no unique way to express a contract: either=20 with the language syntax itself (such as JML [9]) or with a dedicated=20 language, such as Praspel. Both have pros and cons that I won't describe = here (except if you ask). However, having the Aspect Oriented Programming paradigm would be very=20 appreciated. It would avoid a lot of instrumentations and static analyzes= =2E Regards. [1] https://en.wikipedia.org/wiki/Praspel [2] http://hoa-project.net/En/Literature.html#Research [3] http://keynote.hoa-project.net/Amost12/EDGB12.pdf [4] https://github.com/hoaproject/Compiler (documentation is under=20 translation) [5] http://keynote.hoa-project.net/Cstva13/EGB13.pdf [6] https://github.com/hoaproject/Praspel/tree/master/AssertionChecker [7] http://atoum.org/ [8] https://github.com/hoaproject/Hoathis-Atoum [9] https://en.wikipedia.org/wiki/Java_Modeling_Language --=20 Ivan Enderlin Developer of Hoa http://hoa-project.net/ PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis) http://disc.univ-fcomte.fr/ and http://www.inria.fr/ Member of HTML and WebApps Working Group of W3C http://w3.org/