Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98182 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98138 invoked from network); 4 Feb 2017 16:09:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Feb 2017 16:09:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=php-lists@koalephant.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php-lists@koalephant.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain koalephant.com designates 206.123.115.54 as permitted sender) X-PHP-List-Original-Sender: php-lists@koalephant.com X-Host-Fingerprint: 206.123.115.54 mail1.25mail.st Received: from [206.123.115.54] ([206.123.115.54:57378] helo=mail1.25mail.st) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 73/74-38491-CBCF5985 for ; Sat, 04 Feb 2017 11:09:32 -0500 Received: from [10.0.1.63] (unknown [183.89.47.214]) by mail1.25mail.st (Postfix) with ESMTPSA id 11C1560462; Sat, 4 Feb 2017 16:09:22 +0000 (UTC) Content-Type: multipart/alternative; boundary="Apple-Mail=_05BEE45D-720C-4A3C-9AAE-E685A470299A" Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) In-Reply-To: Date: Sat, 4 Feb 2017 23:09:16 +0700 Cc: internals Message-ID: <99D2DDA5-0C1B-4DE0-B91F-DB9004A75327@koalephant.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> <119a1b84-edff-424c-99ba-fd14cbc23ce4@Spark> <75d6f740-92ee-4906-a668-f8c83039d300@Spark> To: ilija.tovilo@me.com X-Mailer: Apple Mail (2.3124) Subject: Re: [PHP-DEV] [RFC][Discuss] Arrow Functions From: php-lists@koalephant.com (Stephen Reay) --Apple-Mail=_05BEE45D-720C-4A3C-9AAE-E685A470299A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi Ilija, For some reason I don=E2=80=99t see your original reply yet. Anyway=E2=80=A6= > On 4 Feb 2017, at 22:48, ilija.tovilo@me.com wrote: >=20 > Ah, my example was of course wrong again -.- >=20 > The caller should=E2=80=99ve looked like this (although I think you = get the point): >=20 > ```Swift > fetchUsers { users in > // `users` is inferred to be an array of `User`s > } > ``` >=20 > Regards >=20 >=20 > On 4 Feb 2017, 16:41 +0100, ilija.tovilo@me.com, wrote: >> Hey Stephen >>=20 >>> You don't *have to* specify types at all. If you want to use PHP = without verifying/requiring types, thats your prerogative, but given the = recent improvements to allow scalar type hinting, I think it=E2=80=99s a = mistake to say that *any* use of type hints is =E2=80=9Cnot = recommended=E2=80=9D. >>=20 >> Sure you don=E2=80=99t but then you loose all the benefits of = specifying types. We want typing but only if we don=E2=80=99t have to = specify types all over the place. I really dislike having to add PHPDocs = everywhere just to get some proper autocompletions. >>=20 You=E2=80=99re really starting to lose me now. You want types but = don=E2=80=99t want to define them, and you=E2=80=99re somehow mixing = phpdoc into this. Ultimately the common example everyone has for arrow functions/short = closures is something like array_map or array_filter. Currently PHP has zero support for Foo[] (or array if you prefer) = as a type hint. In *theory* an IDE could use the calling scope=E2=80=99s = context (assuming the source of the array is purely local or from = arguments/return values that are typed) to infer types, but I haven=E2=80=99= t seen it, and I would likely still use type hints, to cover the case = where something changes elsewhere. >>> I'm not sure if you've mixed up your terms of if I'm too tired but I = don't understand what you mean here. The short arrow function *is* the = callee, and that=E2=80=99s where you=E2=80=99re suggesting we = shouldn=E2=80=99t use type hints. >>=20 >> Sorry, that was confusing. I was thinking of a situation like this = one: >>=20 >> ```Swift >> func fetchUsers(callback: ([User]) -> Void) { >> ... >> } >> ``` >>=20 >> So, the callee (`fetchUsers`) defines what the provided closure must = look like. >> The caller, on the other hand, doesn=E2=80=99t have to specify that = again as you=E2=80=99re just repeating yourself. >>=20 >> ```Swift >> fetchUsers { user in >> // `user` is inferred to be a `User` object >> } >> ``` >>=20 >> So I don=E2=80=99t think the burden of providing typing information = should be on the caller providing the closure. >>=20 Ok so yes, you=E2=80=99re talking about the same thing as the two = RFC=E2=80=99s I linked to. I would love to be able to say =E2=80=9CI = expect a callable that accepts Foo and returns an int=E2=80=9D, but = again, PHP doesn=E2=80=99t support that now, and frankly that doesn=E2=80=99= t negate the need for type hints on short functions. >>> The whole issue with that is that using a pipe character could make = things much less clear/readable if the already established use of pipe = for =E2=80=9Ctype unions=E2=80=9D (currently used in multi-catch) were = to be implemented for general type hint usage. >>>=20 >>> Note: I=E2=80=99m not saying it=E2=80=99s not possible, but it=E2=80=99= s *much* less readable, and any =E2=80=9Csolution=E2=80=9D just adds = more characters, which is apparently the only reason to not use = function($foo) =3D> $foo in the first place. >>=20 >> But again, that=E2=80=99s personal preference. I like short a precise = and think it=E2=80=99s more readable. Not everyone=E2=80=99s the same. >>=20 >>> For most people readability isn't just about the number of = characters. >>=20 >> A lot of the time it is. What were you saying about not everyone being the same?=20 >> Brains are very good at recognising patterns, they don=E2=80=99t need = large keywords for that. >> As for me, I think it just adds clutter to the actual logic that = I=E2=80=99m interested in. >>=20 --Apple-Mail=_05BEE45D-720C-4A3C-9AAE-E685A470299A--