Re: [PHP-DEV] Re: [RFC] Arrow functions / short closures

This is only part of a thread. view whole thread
  105186
April 9, 2019 22:10 robehickman@gmail.com (Robert Hickman)
> - $waithandles = $this->urls->map(fn($url) => $this->fetcher->fetch($url)); > - $waithandles = $this->urls->map(\($url) => $this->fetcher->fetch($url)); > - $waithandles = $this->urls->map($url ==> $this->fetcher->fetch($url)); > > I would say that when lambda functions occurs in function calls I find the > \ or ==> syntax more readable. >
To me, in that context, '==>' is the most readable as it does not have parentheses on the argument. It's a bit visually noisy with them.
  105190
April 10, 2019 08:01 markus@fischer.name (Markus Fischer)
On 10.04.19 00:10, Robert Hickman wrote:
>> - $waithandles = $this->urls->map(fn($url) => $this->fetcher->fetch($url)); >> - $waithandles = $this->urls->map(\($url) => $this->fetcher->fetch($url)); >> - $waithandles = $this->urls->map($url ==> $this->fetcher->fetch($url)); >> >> I would say that when lambda functions occurs in function calls I find the >> \ or ==> syntax more readable. >> > > To me, in that context, '==>' is the most readable as it does not have > parentheses on the argument. It's a bit visually noisy with them.
I concur, `==>` to me also stands out the most easiest to read without too much parenthesis noise. - Markus
  105192
April 10, 2019 08:33 gadelat@gmail.com (Gabriel O)
Those parentheses are important when having multiple argument

On 10 April 2019 10:02:46 AM Markus Fischer <markus@fischer.name> wrote:

> On 10.04.19 00:10, Robert Hickman wrote: >>> - $waithandles = $this->urls->map(fn($url) => $this->fetcher->fetch($url)); >>> - $waithandles = $this->urls->map(\($url) => $this->fetcher->fetch($url)); >>> - $waithandles = $this->urls->map($url ==> $this->fetcher->fetch($url)); >>> >>> I would say that when lambda functions occurs in function calls I find the >>> \ or ==> syntax more readable. >>> >> >> To me, in that context, '==>' is the most readable as it does not have >> parentheses on the argument. It's a bit visually noisy with them. > > I concur, `==>` to me also stands out the most easiest to read without > too much parenthesis noise. > > - Markus > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php
  105195
April 10, 2019 09:07 markus@fischer.name (Markus Fischer)
Hi, Gabriel,

On 10.04.19 10:33, Gabriel O wrote:
> Those parentheses are important when having multiple argument
Please don't top post, thanks! Thanks for pointing it out, I'm aware. Still `===>` would better stand out to _me_ personally. thanks, - Markus
  105197
April 10, 2019 09:27 benjamin.morel@gmail.com (Benjamin Morel)
I think that the RFC covers a great deal of possible syntaxes and their
tradeoffs.

`==>` requires *a lot* of changes to the current parser, and external
tooling as mentioned by Rowan.

It has not even been specified whether the `==>` syntax could land into PHP
7.4, or could require postponing to PHP 8.0.
I do not think that saving these two little chars `fn` justifies the extra
complexity and possible late adoption, if not by PHP, at least by external
tooling.
Also, extra parser complexity potentially means slower compilation times,
even if it's just during opcache warmup.

@nikic, the RFC does not mention changes to reflection:

- Will arrow functions be accessed through ReflectionFunction as well?
- Will they be distinguishable from regular closures, with a method such as
`isShortClosure()` or `isArrowFunction()`?

Thanks,
Ben



On Wed, 10 Apr 2019 at 11:08, Markus Fischer <markus@fischer.name> wrote:

> Hi, Gabriel, > > On 10.04.19 10:33, Gabriel O wrote: > > Those parentheses are important when having multiple argument > > Please don't top post, thanks! > > Thanks for pointing it out, I'm aware. > > Still `===>` would better stand out to _me_ personally. > > thanks, > - Markus > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >