On 6/6/2017 6:38 AM, Stephen Reay wrote: > As someone who sees limited appeal in short closures (Ok, they may > make for slightly simpler constructs that are slightly too complex > for a regular “collect” type collection method), I see a *lot* of > people spending a *lot* of time to save typing 8 characters > (function). > > If this feature truly is about making it easier to read, then that > should be your goal: make it easy to mentally parse, basically > instantly. Given that even proponents of the approach are admitting > the syntax can get quite hard to understand quickly, perhaps it’s > time to accept that “more characters” !== “harder to read & > understand” and importantly, “less characters” !== “easier to read & > understand”. > > How long does it take someone to type function? A second, maybe two? > How many times are other people going to read that, once it’s been > written? >
I can only agree once more. PHP is verbose, PHP always was verbose, PHP should stay verbose. Not to say that short closures are bad, but searching for the perfect symbol soup seems wrong. We could easily create a syntax that is totally unambiguous and easy on the parser without lots of look-ahead with a new keyword. fn> 42 fn($a, $b)> $a + $b fn($a) (&$b)> $b += $a $a = [fn()> 42]; usort($data, fn(T $a, T $b):int> $a <=> $b); Our (simplified) production rule would be (where brackets denote optional): "fn" [ (" [P] ")" ] [ "(" U ")" ] [ ":" T ] ">" E P := param list U := use list T := return type E := expression (to return the result of) This would also ensure that nobody can use it for more complicated expression, since we are not supporting braces. Anything complex should continue to use the long closure notation, as it is more readable. Extending this for usage with methods would also be quite easy. In that case we can even drop the keyword (methods require a name anyways): final class SomeEnum { // ... public static Foo(): self > new static('foo'); public static Bar(): self > new static('bar'); } -- Richard "Fleshgrinder" Fussenegger
signature.asc
Description: OpenPGP digital signature