Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82244 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81149 invoked from network); 9 Feb 2015 08:48:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2015 08:48:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=pthreads@pthreads.org; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=pthreads@pthreads.org; sender-id=unknown Received-SPF: error (pb1.pair.com: domain pthreads.org from 209.85.220.46 cause and error) X-PHP-List-Original-Sender: pthreads@pthreads.org X-Host-Fingerprint: 209.85.220.46 mail-pa0-f46.google.com Received: from [209.85.220.46] ([209.85.220.46:54228] helo=mail-pa0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 15/06-50460-F5478D45 for ; Mon, 09 Feb 2015 03:48:32 -0500 Received: by mail-pa0-f46.google.com with SMTP id lj1so32429724pab.5 for ; Mon, 09 Feb 2015 00:48:28 -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=TZqt/0FH1tyYiUh0IzTJlOxVhfqFTVRum4ZlYnCDkyk=; b=KMNMf4vWFlPtaJ1D0b6+kvBEjYuJrngqkyOdkmALd9CYddZFio0Bx+9WV63lIrm2ss PSIXrQ2wkLXyRZk6PiP8u677QmF1Sd1+oJsAbN0E4HgE6evNi6OoRZ4hbfBaUfzlDmPg HBJqEDI2y7QK6UvepDQezjtm14w1Xp+yw679b/Mu5bP6xXq956zMkGfBGNszPYwX+9BX Xn4o3DMjACmM/cKreNeQNlDVEnOh2Ej7+EtnLvNcJg3V7JfgIkvdaToDw4IB+jEhj9ch cTDhzqoV/aTwNt7NBUBRxBs6/R/QOfa9/u+v7YYFjbnXBTKf0E1tNOVoozTAfGqqfDGQ sBHg== X-Gm-Message-State: ALoCoQkne2dD6Jgz3FnvTIVqtdb4LcGJTN/lSVfJr9EjBt1hr2bLYMexi15POU2fg5Q6W0TdWjik MIME-Version: 1.0 X-Received: by 10.68.254.1 with SMTP id ae1mr26520852pbd.110.1423471708012; Mon, 09 Feb 2015 00:48:28 -0800 (PST) Received: by 10.70.49.100 with HTTP; Mon, 9 Feb 2015 00:48:27 -0800 (PST) X-Originating-IP: [109.145.22.92] In-Reply-To: References: <54D7ED22.3080001@gmail.com> Date: Mon, 9 Feb 2015 08:48:27 +0000 Message-ID: To: Dmitry Stogov Cc: Stanislav Malyshev , Yasuo Ohgaki , PHP Internals Content-Type: multipart/alternative; boundary=047d7b2e0e03811761050ea3d5e4 Subject: Re: [PHP-DEV] Design by Contract From: pthreads@pthreads.org (Joe Watkins) --047d7b2e0e03811761050ea3d5e4 Content-Type: text/plain; charset=UTF-8 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 > > > --047d7b2e0e03811761050ea3d5e4--