2017-02-03 21:23 GMT+01:00 Levi Morrison <le...@php.net>: > On Fri, Feb 3, 2017 at 12:18 PM, Andrea Faulds <a...@ajf.me> wrote: > > Hi David, > > > > David Rodrigues wrote: > >> > >> Hello 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? > > This is not exactly on topic... unless you are implying you'd prefer > the `|$x| => $x + $y`? Maybe you missed [this][1] message? >
Why is using "function" instead of "fn" not on topic? Thanks to everyone who has participated in the discussion thus far. > Primarily the feedback has been directed at the `fn` keyword. Let me > provide two benefits and drawbacks of using `fn` as a keyword: > 1. `fn` is searchable in search engines and in our manual > Just as "php function" is, too: http://php.net/manual/en/language.functions.php > 2. Is more intuitive than just syntax > As is "function", too. With the added benefit that people are already familiar with it. > However, `fn` does have downsides: > 1. Can break existing code > Which doesn't happen with reusing "function". > 2. We already have a similar keyword `function` > Right, so why not use that? > To that end, I'd like to gauge interest in a pure syntax based > alternative that is similar to Rust and Ruby. > Instead of: > fn(params) => expr > What about: > |params| => expr > This trades the advantages of the keyword for the advantages of pure > syntax, and happens to be two characters shorter. To be explicit: > 1. Preserves 100% backwards compatibility > 2. Avoids having two keywords that both mean "function" > 3. Is not easily searchable in engines or in the manual > 4. Is a tad bit shorter > 1, 2, and 3 are also solved by using "function". 4 is counting characters instead of focusing on readability. There are more drawbacks to that syntax like no parameters looking pretty weird: || => Regards, Niklas > [1]: http://news.php.net/php.internals/98136 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >