Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98157 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12510 invoked from network); 3 Feb 2017 23:57:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Feb 2017 23:57:16 -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.155 cause and error) X-PHP-List-Original-Sender: bjorn.x.larsson@telia.com X-Host-Fingerprint: 81.236.60.155 v-smtpout2.han.skanova.net Received: from [81.236.60.155] ([81.236.60.155:39823] helo=v-smtpout2.han.skanova.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B6/FA-38491-6D815985 for ; Fri, 03 Feb 2017 18:57:12 -0500 Received: from [192.168.7.8] ([195.198.188.252]) by cmsmtp with SMTP id Znj0cy00cvgExZnj0cbv0x; Sat, 04 Feb 2017 00:57:08 +0100 To: Levi Morrison References: <19.45.38491.677D4985@pb1.pair.com> Cc: Niklas Keller , Andrea Faulds , PHP internals Message-ID: <93a03c3e-f5ff-dae5-5705-01c994a630d6@telia.com> Date: Sat, 4 Feb 2017 00:57:07 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfD+hELr50KSpkYNiLLkiO28JuIVcLjUC2i1IFkX0QbNMsVlZ3dAFOff5cMwtiAbJ8q5Kpd4MNfmDxBiKcelj1XcuM5k5vlYBGEkAhpfrHxP1aPELPll5 Mh3/r9NYoZku0aOWIfy5gZuWJ81yjnURLTtLF1A9tF6b/wrqoylLP/41oUZk1zJy/RcnXXoJTtAAJlnfcbTSfJxi9+YbrUrpjCTBdG9hhiiinrJXZoOnLAMy OxedQBRA0WDSw71tcQFc3w== Subject: Re: [PHP-DEV] Re: [RFC][Discuss] Arrow Functions From: bjorn.x.larsson@telia.com (=?UTF-8?Q?Bj=c3=b6rn_Larsson?=) Den 2017-02-03 kl. 21:46, skrev Levi Morrison: > On Fri, Feb 3, 2017 at 1:37 PM, Niklas Keller wrote: >> 2017-02-03 21:23 GMT+01:00 Levi Morrison : >>> On Fri, Feb 3, 2017 at 12:18 PM, Andrea Faulds wrote: >>>> Hi David, >>>> >>>> David Rodrigues wrote: >>>>> Hello folks! >>>>> I just not understand why "function" should be abbreviated. It's about >>>>> "how >>>>> less character better"? I don't see it too much on PHP. I guess that is >>>>> more simple keep what exists current "function", that all knows about >>>>> (that >>>>> should be better than the next example): >>>>> >>>>> $mapped = array_map(function($x) => $x + $y); // vs current: >>>>> $mapped = array_map(function($x) use($y) { return $x + $y }); >>>> >>>> I feel the same way. It would be nice to have shorter syntax, but it >>>> sacrifices readability and familiarity here, and adds yet another new >>>> keyword. >>>> >>>> It also feels inconsistent… isn't "fn" just short for "function"? Why is >>>> it >>>> exclusive to the => syntax? >>> This is not exactly on topic... unless you are implying you'd prefer >>> the `|$x| => $x + $y`? Maybe you missed [this][1] message? >> >> Why is using "function" instead of "fn" not on topic? > I did not ask for general syntax suggestions. What I am asking about > is specifically what the preference people might have between these > two options: > > fn(params) => expr > |params| => expr > > As well as potential issues (thanks, Ilija, for pointing out a > theoretical issue with union types). > > ---- > > As a disclaimer I'm trying to guide the discussion to these two > options, not suppress suggestions I don't like. > I can live with both, maybe with a preference for the last one. Using function with another semantic I don't like at all. Imagine for example if different kind of loops had the same starting keyword (for for everything ;-). Also using fn or || helps when searching in a codebase for all ordinary functions and no arrow ones, e.g. grep 'function(\$' files would give everything with fucntion keyword. Anothe angle I came to think of is if PHP in the future would have async / await functionality. How does that play together with arrow functions? HHVM has some example: https://docs.hhvm.com/hack/async/blocks Anyway, I do appreciate that finally arrow functions in PHP are on the horizon :-) Regards //Björn Larsson