Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82363 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72957 invoked from network); 10 Feb 2015 10:21:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Feb 2015 10:21:19 -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.175 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.175 mail-vc0-f175.google.com Received: from [209.85.220.175] ([209.85.220.175:39297] helo=mail-vc0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 67/D2-47508-F9BD9D45 for ; Tue, 10 Feb 2015 05:21:19 -0500 Received: by mail-vc0-f175.google.com with SMTP id hq12so4324891vcb.6 for ; Tue, 10 Feb 2015 02:21:16 -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=vfmIdysVT9Vy9Nz5LIkOC9KcJlUyCDUIu0kHX7wYt7c=; b=G3aWMyOlFWfRWAaGkUlRMaZ6ei/C8DFoRChz5RHfBYmnWvAp3SnqXHctNlJij7ClsA BtcNXwqXGUbxrCzqTk7CxvBXnEKYi3DAjpEH0mPoZ0upRowoQD3u1uoOs+qBdnfXP1bv avTnukUzucXCMFG1Ax+IhVdw57b5tWx0CTdOma2LryxrbYRKeYHDj5HP5Ahma8g8hqfe 0iq2CEmyJauebKdZDo3kZs4Hj/mzhFRwlJWAL+KZLnIX5Gw0zY9JUqC4Sfw6Jg8ug2TG vy8yJJiCmC1l/HbfnLX5IoJvsORCUS/uIt8DeTv3Y0srmk9W/Ne60wTJSTE5ERkDFccv IiCw== X-Gm-Message-State: ALoCoQnr9LHqvMhBMKK3Ay5jM8O/HesMgqsVLifmePLpGeyibz1+eW4zwTb+Q7q3iFvtjPaUf7lhJ2OTZ9Jikvp8oZuM2H7D2syFPb8Fzu/AGpocefz7eBMgFz6HnoUf3SK7e0ZU4aXdov4EVC7CvblYYo1dtPfovQ== MIME-Version: 1.0 X-Received: by 10.221.44.65 with SMTP id uf1mr13784522vcb.46.1423563676016; Tue, 10 Feb 2015 02:21:16 -0800 (PST) Received: by 10.52.74.73 with HTTP; Tue, 10 Feb 2015 02:21:15 -0800 (PST) In-Reply-To: References: <54D7ED22.3080001@gmail.com> Date: Tue, 10 Feb 2015 14:21:15 +0400 Message-ID: To: Joe Watkins Cc: Patrick Schaaf , internals , Yasuo Ohgaki Content-Type: multipart/alternative; boundary=001a11c3ea3c397d1c050eb93f82 Subject: Re: [PHP-DEV] Design by Contract From: dmitry@zend.com (Dmitry Stogov) --001a11c3ea3c397d1c050eb93f82 Content-Type: text/plain; charset=UTF-8 D uses block syntax: ensure(ret) { } In this case, passing 'ret' as a 'parameter' looks more or less natural. In our case, two sets of brackets looks weird. Predefined variable or constant looks better. A agree, __RETURN__ is longer than $ret, but it also won't conflict with other variables. I don't see a perfect solution yet. may be something similar to Smaltalk block syntax: return(, [, ]) function add($a, $b) return($ret, $ret > 0) { return $a + $b; } Thanks. Dmitry. On Tue, Feb 10, 2015 at 1:03 PM, Joe Watkins wrote: > The solution D uses is allowing the programmer to declare the name of the > return value like, we could do something like: > > public function method() > return ($result) ($result <= 10 && $result >= 0) { > return 5; > } > > If you didn't need the result, were working with a scope variable, or > maybe even a param taken by reference: > > public function method() > return ($expr) { > /* ... */ > } > > I'm not keen on __CONSTANTS__, it's long, and if you have the choice to > name the variable you have the option of making the expression ... > expressive ... > > Cheers > Joe > > On Tue, Feb 10, 2015 at 9:48 AM, Dmitry Stogov wrote: > >> I think __RETURN__ is better than $ret. >> >> Dmitry. >> >> On Tue, Feb 10, 2015 at 12:43 PM, Patrick Schaaf wrote: >> >>> Am 10.02.2015 09:29 schrieb "Dmitry Stogov" : >>> > >>> > I cnahged $> into $ret, because $> just won't work. Some better >>> solution is welcome. >>> >>> Also think $> would be awful. Don't like $ret either. What about a magic >>> constant __RETURN__ or __RESULT__? This would stand out very well when >>> glancing at the expression, would fit in with naming of other magic >>> constants, and might even be made to work in finally blocks, where the same >>> need for access to the returned value exists. >>> >>> best regards >>> Patrick >>> >> >> > --001a11c3ea3c397d1c050eb93f82--