Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71759 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99784 invoked from network); 29 Jan 2014 22:13:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jan 2014 22:13:41 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.49 mail-wg0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:53658] helo=mail-wg0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 23/38-52228-41D79E25 for ; Wed, 29 Jan 2014 17:13:40 -0500 Received: by mail-wg0-f49.google.com with SMTP id a1so4711546wgh.4 for ; Wed, 29 Jan 2014 14:13:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=MSiUf1PwNyViXeTuYNqklLhPLz9pcU5qVqfWTnrutdI=; b=dC7ISEm8kWAhYCW684CN/hbiNFrgHATJxR7+DdpGGUhZOa17bUFUb2r5ts85w4Zj4Y dDT7X0jstsMxbTzpxCe+2kxz/PhS5yLiKlT5O7sH4MxuFac2O1W3+KO2KAvQaLXckS1t m7PcpMRiqoeLs3s6e2NTdBiwhjWsk1AnRMR4sY31roNDhQNiRfACMOGyPK1zkLVdYeHG 2CYk9PmtGIXnWuRfvLcFg5SHh9iQmwefp/YufX7+INFRr/e4/mxriuBDBoIRF9xJ8l9r 5kml7uGmt9C3tNsZb5D7Ow7G90zbO7oOLkobw5LpxE5sKkxXfkoyBsONjsmC4b7prZgz ZSKw== X-Received: by 10.194.173.163 with SMTP id bl3mr6721987wjc.10.1391033617133; Wed, 29 Jan 2014 14:13:37 -0800 (PST) Received: from [192.168.0.2] (cpc19-brig17-2-0-cust25.3-3.cable.virginm.net. [81.101.201.26]) by mx.google.com with ESMTPSA id cm5sm8206082wid.5.2014.01.29.14.13.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 29 Jan 2014 14:13:35 -0800 (PST) Message-ID: <52E97D08.1090907@gmail.com> Date: Wed, 29 Jan 2014 22:13:28 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 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: 7bit Subject: Re: [PHP-DEV] DbC for PHP? From: rowan.collins@gmail.com (Rowan Collins) On 28/01/2014 11:05, Alexander Lisachenko wrote: > Here is my one-minute implementation with Go! AOP framework. [...] > > class Test > { > /** > * @Contract("strlen($foo) > 6") > */ > public function bar($foo) > { > echo $foo; > } > } So, dozens of lines of boilerplate, Reflection, and other obscure features (including, presumably, a userland implementation of annotations) and the end result is ... an assertion. The pre-condition is not being added as an aspect, it's hard-coded right there next to the function, doing exactly the same thing as adding this single line at the top of the function: assert('strlen($foo) > 6'); Post-conditions are a little trickier: they require a single-point-of-return (something which has its advocates anyway, and could easily be enforced as a project coding standard) and potentially introduce an intermediate variable that could otherwise be skipped. But this seems like a lot of overhead to work around that. Now, I realise that this was a simple example, but I would be interested to see what such an approach could actually offer in return for its complexity. Regards, -- Rowan Collins [IMSoP]