Re: Re: [RFC][Discuss] Arrow Functions
| From: | Björn Larsson | Date: | Fri, 03 Feb 2017 23:57:07 +0000 |
| Subject: | Re: Re: [RFC][Discuss] Arrow Functions | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98157@lists.php.net to get a copy of this message | ||
Den 2017-02-03 kl. 21:46, skrev Levi Morrison:
On Fri, Feb 3, 2017 at 1:37 PM, Niklas Keller <me@kelunik.com> wrote:last one. Using function with another semantic I don't like at all. Imagine for example if different kind of loops had the same starting keyword (for for everything ;-). Also using fn or || helps when searching in a codebase for all ordinary functions and no arrow ones, e.g. grep 'function(\$' files would give everything with fucntion keyword. Anothe angle I came to think of is if PHP in the future would have async / await functionality. How does that play together with arrow functions? HHVM has some example: https://docs.hhvm.com/hack/async/blocks Anyway, I do appreciate that finally arrow functions in PHP are on the horizon :-) Regards //Björn Larsson2017-02-03 21:23 GMT+01:00 Levi Morrison <levim@php.net>:I did not ask for general syntax suggestions. What I am asking about is specifically what the preference people might have between these two options:On Fri, Feb 3, 2017 at 12:18 PM, Andrea Faulds <ajf@ajf.me> wrote:Why is using "function" instead of "fn" not on topic?Hi David, David Rodrigues wrote:This is not exactly on topic... unless you are implying you'd prefer theHello folks! I just not understand why "function" should be abbreviated. It's about "how less character better"? I don't see it too much on PHP. I guess that is more simple keep what exists current "function", that all knows about (that should be better than the next example): $mapped = array_map(function($x) => $x + $y); // vs current: $mapped = array_map(function($x) use($y) { return $x + $y });I feel the same way. It would be nice to have shorter syntax, but it sacrifices readability and familiarity here, and adds yet another new keyword. It also feels inconsistent… isn't "fn" just short for "function"? Why is it exclusive to the => syntax?|$x| => $x + $y? Maybe you missed [this][1] message?fn(params) => expr |params| => exprAs well as potential issues (thanks, Ilija, for pointing out a theoretical issue with union types). ---- As a disclaimer I'm trying to guide the discussion to these two options, not suppress suggestions I don't like. I can live with both, maybe with a preference for the