Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82189 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77794 invoked from network); 8 Feb 2015 23:11:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2015 23:11:52 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.179 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.192.179 mail-pd0-f179.google.com Received: from [209.85.192.179] ([209.85.192.179:39678] helo=mail-pd0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D9/0A-26926-73DE7D45 for ; Sun, 08 Feb 2015 18:11:52 -0500 Received: by pdjy10 with SMTP id y10so4386071pdj.6 for ; Sun, 08 Feb 2015 15:11:49 -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=iWRUW7PVXtmtOANlUi+1uLh/uSbesyy68mWPbPY0B3A=; b=tWXJvsYcL0wO1u9zej5Rxs6vJEr6rKuBbzVp6/KyKAJdBudE05zr23t8kj4qOOjsf2 Emh79EEGHyDuZTnVB02F5QG9+paofhGBh5vAn46pqCb2gm7oR4pSCdv4gNOF7cYf+vEz 1gqYzBtr2YwiskhSUBiOD0u0pogE6nR/e/eEmeRkPgbM5RpaballOgoMv+B7AfU2irvR bbt5a8u8zz4y4KgCHa+Q9/pYL4Lb5ZybIByn+Je79cV6wXPAsSdD5qFLgvBE+Xv43hg5 fovULDB1YKFx6qEBB4L7HO1xtaFwI4o4RDUeS5eVM/kxn+/CyMcZ9BZhogKraQP9XYls wipw== X-Received: by 10.70.140.162 with SMTP id rh2mr23843084pdb.131.1423437109332; Sun, 08 Feb 2015 15:11:49 -0800 (PST) Received: from Stas-Air.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id fl2sm14463776pab.2.2015.02.08.15.11.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Feb 2015 15:11:48 -0800 (PST) Message-ID: <54D7ED22.3080001@gmail.com> Date: Sun, 08 Feb 2015 15:11:30 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Dmitry Stogov , Yasuo Ohgaki , PHP Internals References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Design by Contract From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > Following our conversation, I tried to imagine how DbC should look like in > PHP from user perspective. Finally, I was influenced by the semantic > proposed in D, and syntax proposed for Java. So, these are my initial > thoughts: > > For php it may look like the following: > > function foo() > requre() > ensure() > { > ... > } Why not do it simpler? function foo() { // require assert(); ... // ensure assert(); } I'm oversimplifying a bit, but in general, why we need more places to have code in the function than the actual code of the function? It would be harder to parse, to read, to maintain, to debug, to profile, etc. and I'm not sure what exactly it provides that can't be done by plain regular code inside the function. If we're concerned about the costs of assert, we could make special provision in the compiler for zero-cost asserts. It doesn't require moving code out of the function. -- Stas Malyshev smalyshev@gmail.com