Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82247 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86259 invoked from network); 9 Feb 2015 09:01:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2015 09:01:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.176 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.176 mail-vc0-f176.google.com Received: from [209.85.220.176] ([209.85.220.176:59847] helo=mail-vc0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/17-50460-C7778D45 for ; Mon, 09 Feb 2015 04:01:48 -0500 Received: by mail-vc0-f176.google.com with SMTP id la4so578469vcb.7 for ; Mon, 09 Feb 2015 01:01:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=y7OHIL1Yq6rMJ3cISD42Rr4f5Iz/Tffn5nyVRhdI+oM=; b=YF6c84dIhcDDdRW3+4ErLPN9j3LowL1ytEoLGol8fmvgmqJzwGYH5UjAbb2cinCUYx CPGcbHEc+Vq6a7uEqi++esNyRRVAGv5zmaUK3/dfZ4BjDewVAbtXLMKYCWsdyppduvKP fb/oyGFd+8cCqulBNn8Tchc2f82j1Ghgo/wLvBRxDszpQyskbzGP9FpaJNK1tKLZ3d+/ 2cd+TQPxFGzUGZHTrMil7rEqLnqJCFBm7hIZNnHisWes+LAK7QDwjrRA5GtGSweN6UJf fDptT0EixNMZE8PvYT0anSwur/cKIu1ijzcaHkkoMg2R0SqwLvEM7xZX7IVCfChY+msH PGOQ== X-Gm-Message-State: ALoCoQnO2lLRqXQrnwRblvkVaSQwKAmQahslEh6R7R6c3JaYxqTE1X0D1VlcdIOoXH5V1O9AUBkoxW1oJlGVi9ShPwYXX6yJD8Wcp7U+UDvHrtLsMty0bBJIZGdKa91BU943P4HVFIt4GWVhxawy8egMWusuILjZ6Q== MIME-Version: 1.0 X-Received: by 10.221.21.131 with SMTP id qs3mr9517140vcb.33.1423472506130; Mon, 09 Feb 2015 01:01:46 -0800 (PST) Received: by 10.52.74.73 with HTTP; Mon, 9 Feb 2015 01:01:45 -0800 (PST) In-Reply-To: References: <54D7ED22.3080001@gmail.com> Date: Mon, 9 Feb 2015 13:01:45 +0400 Message-ID: To: Joe Watkins Cc: Stanislav Malyshev , Yasuo Ohgaki , PHP Internals Content-Type: multipart/alternative; boundary=001a11339f8a136728050ea40580 Subject: Re: [PHP-DEV] Design by Contract From: dmitry@zend.com (Dmitry Stogov) --001a11339f8a136728050ea40580 Content-Type: text/plain; charset=UTF-8 Usage of "return" is a good idea. The more heads the better result :) Thanks. Dmitry. On Mon, Feb 9, 2015 at 11:48 AM, Joe Watkins wrote: > Morning internals, > > I really liked the original idea Dmitry had, with the D-ish syntax. > > We could use require and return like: > > function foo() > require(input-expr) > return(output-expr) { > /* ... */ > } > > to avoid adding more keywords. > > I'd really appreciate seeing this as an option in the RFC. > > Cheers > Joe > > On Mon, Feb 9, 2015 at 8:44 AM, Dmitry Stogov wrote: > >> It's nothing wrong here. It's just a concept that cares about constraints >> definition more. >> >> So, DbC with asserts spread among the code is like OOP without classes. >> >> Thanks. Dmitry. >> >> >> On Mon, Feb 9, 2015 at 2:11 AM, Stanislav Malyshev >> wrote: >> >> > 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 >> > >> > > --001a11339f8a136728050ea40580--