Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104761 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36124 invoked from network); 16 Mar 2019 00:53:43 -0000 Received: from unknown (HELO NAM01-BN3-obe.outbound.protection.outlook.com) (40.92.0.25) by pb1.pair.com with SMTP; 16 Mar 2019 00:53:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=j63PxlwISX1yzx3hekihLLGRrcyA3fr31syExM1lEus=; b=H8LbWMq09r2tMaCZaXjRsKiUXRy4pjRcptKSa67dXPXbjLF9Fy4cmQ/jUrc0717RxNHnLm+26hFjs94jPgrtRhw+KYd23YyYFfFlP6Yk4YSO5Ygv0e7dOlcUwxrji3rw1w4/J0IppmzXE5U340lgtP6ogrRx0mOxGH23BpqLoxsb7fZxCJJ1cNjwCvKUf+AY6ermOSaCDL/IfmgCwgQdIMTHcPLjB6nyD3KWb5hWn6DyTz+XtHD4jK3BxlH6iIxvbQFzpKT/AkWLye5zSavAnjQc7cPaJwBnMtXgZ4QltnFQfGnFXp0Q3I2glT452VtRZLJ7jFA7hyiZc6MRmxiLZQ== Received: from BY2NAM01FT041.eop-nam01.prod.protection.outlook.com (10.152.68.59) by BY2NAM01HT106.eop-nam01.prod.protection.outlook.com (10.152.69.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1709.13; Fri, 15 Mar 2019 21:44:26 +0000 Received: from DM5PR06MB2857.namprd06.prod.outlook.com (10.152.68.53) by BY2NAM01FT041.mail.protection.outlook.com (10.152.68.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.13 via Frontend Transport; Fri, 15 Mar 2019 21:44:26 +0000 Received: from DM5PR06MB2857.namprd06.prod.outlook.com ([fe80::2580:dff:c36e:ea31]) by DM5PR06MB2857.namprd06.prod.outlook.com ([fe80::2580:dff:c36e:ea31%6]) with mapi id 15.20.1709.011; Fri, 15 Mar 2019 21:44:26 +0000 To: Josh Di Fabio CC: Nikita Popov , PHP internals Thread-Topic: [PHP-DEV] Re: [RFC] Arrow functions / short closures Thread-Index: AQHU2nxyT92G5anxlkG9179pVR0E5aYLhuNtgADrwQCAALyrjA== Date: Fri, 15 Mar 2019 21:44:26 +0000 Message-ID: References: , In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:DE9DCCDD2DF47239E1C37406BD930DD7356A3F7E738C6D833DA69A04C9095B29;UpperCasedChecksum:D09E912CE830D631B14A46B71BB5056A82CC5407645B6698152F396A54FE832A;SizeAsReceived:7152;Count:45 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [ps6qVXphhJ51Z4eXTveZBbtn/9bVEgE9] x-ms-publictraffictype: Email x-incomingheadercount: 45 x-eopattributedmessage: 0 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(20181119110)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031322404)(2017031323274)(1601125500)(1603101475)(1701031045);SRVR:BY2NAM01HT106; x-ms-traffictypediagnostic: BY2NAM01HT106: x-microsoft-antispam-message-info: MKYScXGQ8le2rSLTcevAxHNw4efGK7IBqSxRqgSeBDw2AbHrcRGU/gFc+lzcjl7b Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 11f6b5cf-8649-45d2-7e49-08d6a98f6581 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Mar 2019 21:44:26.7496 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2NAM01HT106 Subject: Re: [PHP-DEV] Re: [RFC] Arrow functions / short closures From: theodorejb@outlook.com (Theodore Brown) On Fri, March 15, 2019 at 4:45 AM Josh Di Fabio wro= te:=0A= =0A= > I'd certainly be on board with the fn() syntax, but the backslash=0A= > syntax has definitely grown on me. To me, all of the examples in=0A= > Theodore's email are very readable and I find that the backslash makes=0A= > it very easy to identify arrow functions when grokking.=0A= >=0A= > `array_filter($numbers, \$n =3D> $n % 2);`=0A= > vs.=0A= > `array_filter($numbers, fn($n) =3D> $n % 2);`=0A= >=0A= > When grokking these two pieces of code, I immediately see `\$n =3D> $n % = > 2`=0A= > as a single unit, whereas in the latter example I instinctively=0A= > (and incorrectly) interpret "fn($n)" as an expression.=0A= >=0A= > When parens are required, the difference is obviously reduced, but I=0A= > think I still prefer the backslash syntax since the LHS doesn't grok=0A= > as a function call.=0A= >=0A= > `reduce($numbers, \($x, $y) =3D> $x + $y);`=0A= > vs.=0A= > `reduce($numbers, fn($x, $y) =3D> $x + $y);`=0A= > =0A= > That said, I'd personally take either syntax gladly.=0A= =0A= =0A= You have a good point about `fn()` looking like an expression.=0A= That said, since it would be a keyword IDEs will highlight it=0A= differently which should help avoid confusion.=0A= =0A= Regarding the backslash syntax, I forgot to check how it looks with=0A= by-reference passing and returning before I sent my email. Here are=0A= those examples:=0A= =0A= ```php=0A= fn(&$x) =3D> $x;=0A= fn&($x) =3D> $x;=0A= =0A= // vs.=0A= =0A= \(&$x) =3D> $x;=0A= \&($x) =3D> $x;=0A= =0A= // unclear if passing or returning by reference=0A= \&$x =3D> $x;=0A= =0A= // and worst of all...=0A= fn&(&$x) =3D> $x;=0A= =0A= // vs.=0A= \&(&$x) =3D> $x;=0A= ```=0A= =0A= I have to admit that the `fn` prefix is a little more readable for=0A= these use cases (though I've never actually seen a real function=0A= using by-reference passing and returning at the same time).=0A= =0A= -Theodore Brown=