Re: [RFC]Discuss] Syntax for Arrow Functions

From: Date: Fri, 09 Jun 2017 11:23:43 +0000
Subject: Re: [RFC]Discuss] Syntax for Arrow Functions
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  Groups: php.internals 
Request: Send a blank email to internals+get-99467@lists.php.net to get a copy of this message
Den 2017-06-09 kl. 02:13, skrev Sara Golemon:
On Thu, Jun 8, 2017 at 4:56 PM, Björn Larsson <bjorn.x.larsson@telia.com> wrote:
You have a good point here! I think one then should evaluate both the implementation, which apparently is not so great and how the feature itself has been received. I mean is it heavily used and what is the user feedback? E.g. are users happy with the syntax and how do they use it.
As I already mentioned, the HHVM implementation is hackish, but the reception around Facebook about the feature itself was SUPER positive. Particularly when paired with collections. $someDict->map($v ==> $v * 2)->filter($v ==> $v % 3); just reads way cleaner than the old expressions. FWIW, (with my HHVM hat on) we'd also discussed that we wouldn't be too bothered if PHP went with a different syntax as it would ease pressure to match behavior on a feature that's already widely deployed internally. So don't worry about picking a symbol based on what Hack uses. Pick what makes sense for PHP. For my part, I care FAR more that we get short closures than what gymnastics my fingers have to partake. Well, that is a good indication that this feature is really needed
and that the short syntax isn't seen as cumbersome in the HACK comunity at least. If I be so bold then, to say that the main issue with short syntax in PHP is the implementation, not the syntax. But of course, not all like the short syntax... If I take the liberty in using the example above on our option list: 1. $someDict->map(fn($v) => $v * 2)->filter(fn($v) => $v % 3); 2. $someDict->map(function($v) => $v * 2)->filter(function($v) => $v % 3); 3. $someDict->map($v ==> $v * 2)->filter($v ==> $v % 3);
4. $someDict->map(($v) => $v * 2)->filter(($v) => $v % 3);        // Ambiguous
5. $someDict->map([]($v) => $v * 2)->filter([]($v) => $v % 3); Old proposals: 6. $someDict->map($v ~> $v * 2)->filter($v ~> $v % 3); 7. $someDict->map(lambda($v) => $v * 2)->filter(lambda($v) => $v % 3); Interesting example, it shows one benefit for arrow functions compared to anonymous function is not saving keystrokes, but improving readability when the arrow function is embedded into something else. Also having a short syntax improves the readability further in my eyes. But using "lambda" has the benefit that we here talk about something different compared to "function" and what it is. r//Björn

« previous php.internals (#99467) next »