Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99467 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55316 invoked from network); 9 Jun 2017 11:23:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Jun 2017 11:23:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=bjorn.x.larsson@telia.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=bjorn.x.larsson@telia.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain telia.com from 81.236.60.154 cause and error) X-PHP-List-Original-Sender: bjorn.x.larsson@telia.com X-Host-Fingerprint: 81.236.60.154 v-smtpout1.han.skanova.net Received: from [81.236.60.154] ([81.236.60.154:38953] helo=v-smtpout1.han.skanova.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4D/0D-27119-4458A395 for ; Fri, 09 Jun 2017 07:23:49 -0400 Received: from [192.168.8.16] ([94.254.95.82]) by cmsmtp with SMTP id JI13dkR1TPPY2JI13dmmeA; Fri, 09 Jun 2017 13:23:46 +0200 To: Sara Golemon Cc: Rowan Collins , PHP internals References: <7eaef49b-bf60-9aa1-e812-8430164e3178@garfieldtech.com> <3F920987-38CB-42DD-888D-824430C36F14@gmail.com> <2f9e73c9-444a-11d0-459a-e261ea8a7080@telia.com> <4077c099-2247-c3c1-7dee-02a6b25f8586@fleshgrinder.com> <559b73f7-c40f-e593-f0e1-51b56210d7cb@telia.com> <2053A608-6B66-42FB-A6D7-7CC64E94DA6A@koalephant.com> <4FBDE643-1EBC-485A-A39F-7E28C5D4807A@koalephant.com> <034f3ebf-95b8-a7cf-1279-77c7cf0424d7@gmail.com> <46143e7c-ef75-7c05-eaa9-98c8f3b405f1@telia.com> Message-ID: Date: Fri, 9 Jun 2017 13:23:43 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: sv X-CMAE-Envelope: MS4wfNZmIObNNSlYOf8FmtOutSyNRzOj43klxnrAktOs/A737OO5DDA4Et13OOl9BggLg64bYOyw2sxmvt2yLEZUP28Bv42CF0CPelU8Elfyh72dOomNDXUm iBbWQcy03VgI0dupGeYdDL94mpBto7dwyBr7gkrletKDvFgNVxfxYr1r8/CoktZUsU79FatZKL1x8XKn1FEc0i7MFUrt+z/T1kkLrxizn1NfL8Gy8tLuOhcd D1AU/0WFUBFo2T6JAIVGDA== Subject: Re: [PHP-DEV] [RFC]Discuss] Syntax for Arrow Functions From: bjorn.x.larsson@telia.com (=?UTF-8?Q?Bj=c3=b6rn_Larsson?=) Den 2017-06-09 kl. 02:13, skrev Sara Golemon: > On Thu, Jun 8, 2017 at 4:56 PM, Björn Larsson wrote: >> You have a good point here! I think one then should evaluate >> both the implementation, which apparently is not so great and >> how the feature itself has been received. >> >> I mean is it heavily used and what is the user feedback? E.g. are >> users happy with the syntax and how do they use it. >> > As I already mentioned, the HHVM implementation is hackish, but the > reception around Facebook about the feature itself was SUPER positive. > Particularly when paired with collections. $someDict->map($v ==> $v * > 2)->filter($v ==> $v % 3); just reads way cleaner than the old > expressions. > > FWIW, (with my HHVM hat on) we'd also discussed that we wouldn't be > too bothered if PHP went with a different syntax as it would ease > pressure to match behavior on a feature that's already widely deployed > internally. So don't worry about picking a symbol based on what Hack > uses. Pick what makes sense for PHP. For my part, I care FAR more > that we get short closures than what gymnastics my fingers have to > partake. > Well, that is a good indication that this feature is really needed and that the short syntax isn't seen as cumbersome in the HACK comunity at least. If I be so bold then, to say that the main issue with short syntax in PHP is the implementation, not the syntax. But of course, not all like the short syntax... If I take the liberty in using the example above on our option list: 1. $someDict->map(fn($v) => $v * 2)->filter(fn($v) => $v % 3); 2. $someDict->map(function($v) => $v * 2)->filter(function($v) => $v % 3); 3. $someDict->map($v ==> $v * 2)->filter($v ==> $v % 3); 4. $someDict->map(($v) => $v * 2)->filter(($v) => $v % 3); // Ambiguous 5. $someDict->map([]($v) => $v * 2)->filter([]($v) => $v % 3); Old proposals: 6. $someDict->map($v ~> $v * 2)->filter($v ~> $v % 3); 7. $someDict->map(lambda($v) => $v * 2)->filter(lambda($v) => $v % 3); Interesting example, it shows one benefit for arrow functions compared to anonymous function is not saving keystrokes, but improving readability when the arrow function is embedded into something else. Also having a short syntax improves the readability further in my eyes. But using "lambda" has the benefit that we here talk about something different compared to "function" and what it is. r//Björn