Re: Arrow function expressions in PHP
| From: | Bishop Bettini | Date: | Thu, 01 Oct 2015 17:12:19 +0000 |
| Subject: | Re: Arrow function expressions in PHP | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88613@lists.php.net to get a copy of this message | ||
On Thu, Oct 1, 2015 at 12:28 PM, Anthony Ferrara <ircmaxell@gmail.com>
wrote:
> Nikita and all,
>
> > I don't think there was a dozen of different ideas, I could only find
> those
> > about
lambda(arg-list; use-list; expression) and
> > variations of it with
> > different keywords and different return-type syntax.
> > I do understand that this is quite subjective, but neither this syntax
> nor
> > fn(arg-list; use-list) expression look obvious and easily
> > readable to
> me.
>
> The problem is that semicolons are non-obvious, especially in a
> context where commas are used (and traditionally used).
>
> Example, tell the difference quickly between
>
> fn($a, $b; $c) => $a + $b + $c;
>
> and
>
> fn($a; $b, $c) => $a + $b + $c.
>
> At a glance, they are identical. You have to actually look at each
> item to realize that there's a difference. At least with use() there's
> a syntactical separator there to draw your eye to the contextually
> relevant information.
True. But a developer can mitigate with judicious white-space:
fn($a, $b ; $c) => $a+$b+$c
Or we can figure out some other such symbol. Worse casing no white space,
brain storming:
fn($a,$b:$c) => $a+$b+$c // not much better
fn($a,$b!$c) => $a+$b+$c // better, but looks like not
fn($a,$b&$c) => $a+$b+$c // lost in the noise, looks like bitwise
fn($a,$b%$c) => $a+$b+$c // perl jibberish, looks modulo
fn($a,$b--$c) => $a+$b+$c // multi-char, looks like decrement
fn($a,$b::$c) => $a+$b+$c // maybe, kinda confusing
// my favorite
fn($a, $b @ $c) => $a + $b + $c;
// vs.
function ($a, $b) use ($c) { return $a + $b + $c; }
// a space savings of 100%
// unambiguous parsing
// no backtracing
// no new rules to learn about scope pulling
// works if we later support '*' for scope pulling