Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98165 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35605 invoked from network); 4 Feb 2017 05:01:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Feb 2017 05:01:11 -0000 Authentication-Results: pb1.pair.com header.from=aaron@trowski.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=aaron@trowski.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain trowski.com designates 199.38.81.6 as permitted sender) X-PHP-List-Original-Sender: aaron@trowski.com X-Host-Fingerprint: 199.38.81.6 mercury.negativeion.net Received: from [199.38.81.6] ([199.38.81.6:56578] helo=mercury.negativeion.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 72/2E-38491-41065985 for ; Sat, 04 Feb 2017 00:01:09 -0500 Received: from localhost (localhost [127.0.0.1]) by mercury.negativeion.net (Postfix) with ESMTP id 04CD8475C39E; Sat, 4 Feb 2017 00:01:06 -0500 (EST) X-Virus-Scanned: amavisd-new at negativeion.net Received: from mercury.negativeion.net ([127.0.0.1]) by localhost (mercury.negativeion.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lUCWOqBcWJT7; Sat, 4 Feb 2017 00:01:05 -0500 (EST) Received: from jupiter.local (unknown [173.225.150.231]) by mercury.negativeion.net (Postfix) with ESMTPSA id 7A1C8475C390; Sat, 4 Feb 2017 00:01:05 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) In-Reply-To: <77287A6A-C3E9-4C93-A1F2-2899DAEA8738@koalephant.com> Date: Fri, 3 Feb 2017 23:01:04 -0600 Cc: internals Content-Transfer-Encoding: quoted-printable Message-ID: <545FB7CD-16F6-4F85-B6F1-087039AD5EF1@trowski.com> References: <19.45.38491.677D4985@pb1.pair.com> <611b72db-420f-4963-ab92-0ddf977a0aaa@Spark> <9AF0D2F6-D668-418C-8B96-3320D9D245ED@trowski.com> <5722B01C-A621-4C13-B34B-383B0D9753F9@koalephant.com> <22B18CB2-0383-4D4D-9B55-91A748725AC9@trowski.com> <77287A6A-C3E9-4C93-A1F2-2899DAEA8738@koalephant.com> To: Stephen Reay X-Mailer: Apple Mail (2.3124) Subject: Re: [PHP-DEV] [RFC][Discuss] Arrow Functions From: aaron@trowski.com (Aaron Piotrowski) Hi Stephen, > On Feb 3, 2017, at 10:38 PM, Stephen Reay = wrote: >=20 >=20 >>=20 >> I absolutely agree that it's terrible=E2=80=A6 the point is that = types (even potential future union types) can be used with short = closures, but it certainly doesn't mean they should be. I don't think = confusion with a non-existent and non-recommended way of coding should = be a reason against a particular syntax. >=20 > Using type hints is a part of the language. It even has benefits that = I can absolutely see being used here: >=20 > array_map(function(Foo $x) =3D> $x->bar());=20 >=20 > If Foo is a class/interface with a method of bar, your IDE can know = that it's a valid method to call. >=20 > That of course is in addition to the benefit of getting useful type = errors from PHP itself. You raise a good point about IDEs, types might have a place with short = closures. Still, I don't see union types, if they ever exist, being = common here. Taking your example with the other proposed syntax: array_map(|Foo $x| =3D> $x->bar()); Honestly I'm not sure which is better=E2=80=A6 personal preference at = this point, each has their merits. >>=20 >>> As has been said before, PHP is relatively verbose compared to other = languages. That makes it slightly more characters to type, but it also = makes it absolutely clear what is happening. >>=20 >> Using `function` IMO makes it more likely to confuse a short closure = with a regular closure. Reusing the `function` keyword with different = semantics may result in some confusion. >>=20 >=20 > So we should instead use syntax already used for bit wise OR, and = further confuse the situation when the function has no parameters and = reusing the logical OR operator. Brilliant. This is certainly a downside, though expressions cannot start with a = logical or bitwise OR, so that will help differentiate them. However, it = is hard to argue that `function` could be confusing when something like = `|| =3D> $x ** 2` may be more confusing, so point taken. Regardless, I = still prefer the visual difference since the auto-capture behavior is so = different from other functions. Cheers! Aaron Piotrowski