Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82470 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10056 invoked from network); 11 Feb 2015 11:25:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Feb 2015 11:25:39 -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.170 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.170 mail-vc0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:45344] helo=mail-vc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9A/E3-22055-23C3BD45 for ; Wed, 11 Feb 2015 06:25:39 -0500 Received: by mail-vc0-f170.google.com with SMTP id hq12so933975vcb.1 for ; Wed, 11 Feb 2015 03:25:36 -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=ULxHDuv8zTVoVEft5oX1VFKi/1K76obXDolA2CMABwc=; b=mKg0PQGcFfaNXgBpi3iYxVLsJfanuKlNfVKIOTOwqHaQHom/yr/nSGaJLX0D4VcKW8 fB/4GPSg4896QaZ7267zkM8UOTrMm6PhsHAx/2Jqdr0J5pEimgpJiD4jtyqhppJEWQal oBW3ABhQVTUv5cZWAzs0exeJU9u2GTIHMU9moTeyQHEj60DjjCh0CR63iwECG9H6KeuP Vh7JcjDmGqldoDWof/RrffpaRfaDkE1rpDZ45L6ctpZzDGM0MGwy6yQRLJfyWdl/bmqM PpfrdUMMO5hOEfrRa6emp/XdgjDf7F9gFuxb9yntiptoDsSL0C4vZoaItYkqcKY7GdfA 5soA== X-Gm-Message-State: ALoCoQk7dt0YByRL8QMLFd9Os2vXk4iAnsPYDWnwnahNya59HhjYDudndFeSBB2+/jslXJfCxUXcn+oe6wjW8SPQEqnYL6BFIAgHRFhVUb1DG+uHYxj82480apIkthwCKJgEa3lcX/vTYQxUuG8XoHJ1kUGFhoqaMw== MIME-Version: 1.0 X-Received: by 10.221.2.197 with SMTP id nv5mr18359859vcb.53.1423653936219; Wed, 11 Feb 2015 03:25:36 -0800 (PST) Received: by 10.52.74.73 with HTTP; Wed, 11 Feb 2015 03:25:35 -0800 (PST) In-Reply-To: <54DB0BC0.20304@gmail.com> References: <54DAFD32.3000005@gmail.com> <54DB0BC0.20304@gmail.com> Date: Wed, 11 Feb 2015 15:25:35 +0400 Message-ID: To: Stanislav Malyshev Cc: Joe Watkins , Yasuo Ohgaki , =?UTF-8?Q?Fran=C3=A7ois_Laupretre?= , PHP Internals Content-Type: multipart/alternative; boundary=089e0115fd0226de90050ece433d Subject: Re: [PHP-DEV] Design by Contract From: dmitry@zend.com (Dmitry Stogov) --089e0115fd0226de90050ece433d Content-Type: text/plain; charset=UTF-8 On Wed, Feb 11, 2015 at 10:58 AM, Stanislav Malyshev wrote: > Hi! > > > 1) contracts in doc-commetns https://wiki.php.net/rfc/dbc > > > > /** > > * @requires ($a >= 0) > > */ > > function foo($a) { > > } > > We've spent several years rejecting annotations because no information > can be in comments, not even a little bit, not even a tiny. Now we'd > have full-blown running code in comments? How would this code be > debugged/profiled/interpreted by tools? Writing PHP parser is not easy > right now, but this would turn it into nightmare (what if you have a > comment inside @requires? etc.) > I don't see how this can be implemented in PHP core as well. This approach is for external tools. > > > 2) contracts as part of the language https://wiki.php.net/rfc/dbc2 > > > > function foo($a) > > require($a >= 0) > > { > > } > > This is a step better but still we have the similar issues with > readability, to which reuse of 'require' is added. > > > 3) contracts in annotations > > > > <= 0)>> > > function foo($a) { > > } > > That one actually looks better to me, but: I'm not sure how annotation > syntax is supposed to support expressions or closures, keep AST. > yet more - how it > is supposed to share the scope with the function. I.e., if you define > annotation class/method/function/data structure/whatever it is, what it > is supposed to receive? We may have AST transformation pass that would convert these annotations into assert() and insert them into AST of the function. > Is it some special form of annotation for this > purpose only (meh)? > yes. some special attributes. requires/ensures/invariant > Oh, and <<>> syntax is *ugly* ;) > It's from HHVM. I don't like it as well, please, propose the better one. Thanks. Dmitry. > > -- > Stas Malyshev > smalyshev@gmail.com > --089e0115fd0226de90050ece433d--