Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71712 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82933 invoked from network); 29 Jan 2014 04:18:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jan 2014 04:18:50 -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.217.180 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.217.180 mail-lb0-f180.google.com Received: from [209.85.217.180] ([209.85.217.180:47623] helo=mail-lb0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DF/10-14964-92188E25 for ; Tue, 28 Jan 2014 23:18:49 -0500 Received: by mail-lb0-f180.google.com with SMTP id n15so1081006lbi.11 for ; Tue, 28 Jan 2014 20:18:46 -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=CuwHBFgk3/GEVf8Fhg3bbPbgkD5Nj1aan2407WSxfXs=; b=OCYnE7jswt/dfhW4+/32ZqYLJPZYZ+juYxKvST4J5JRAa0AbUpUyO9k/XVhM+aZpgU ymM+9AcN/vQph6G8aOkCz3dGlgBp5jjCG6+/IVFJTQBoAb5ZCz44zFxICI1H+gt2uWcy WW6HTPr97FX19o0dImm/PuzZntfTbBsB5phvyunVcUSzZU0M8i7vUcj6Fib+T26ioa25 SSDg85+g4D7B+eCZwURe2NWp33tm+jlxTIcBcCn+ui9eumrULAgQ84103CUgMWkQo1ku 27BPPvmFrruwp/bxaCiQqXmrerhBX51wxF9HRGhXPN/i4K/bm4DjabPv/0VDcCeYNKzB Dw5g== X-Received: by 10.152.42.230 with SMTP id r6mr3741434lal.18.1390969126058; Tue, 28 Jan 2014 20:18:46 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.199.37 with HTTP; Tue, 28 Jan 2014 20:18:05 -0800 (PST) In-Reply-To: References: Date: Wed, 29 Jan 2014 13:18:05 +0900 X-Google-Sender-Auth: Q_FdXsh9qIvn2-GZPDOh-J77Gbc Message-ID: To: Sebastian Krebs Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c36780a7013004f1143c0d Subject: Re: [PHP-DEV] DbC for PHP? From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c36780a7013004f1143c0d Content-Type: text/plain; charset=UTF-8 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'. This could damage production code (code executed on production environment) and contract readability. It increases chances of omitting post condition check by mistake. 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. 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 --001a11c36780a7013004f1143c0d--