Jeff Griffiths wrote:
> Antony Dovgal wrote:
> ...
>> Well, to me it matters whether the author is going to care of the
>> thing he's proposing or he's going to disappear right after it's
>> implemented.
> 
> I didn't realize there was a section of the code flagged 'syntactic
> sugar' and only a few people maintained that part. it also seems
> ridiculous to debate a syntax *addition* such as this in terms of
> maintainability. Is it really is hard to maintain this patch to the
> parser? How hard is it to maintain this:
> 
> $array[] = $foo;
> 
> ...vs any other part of the codebase?

Whoa, slow down cowboy!

Any change to the parser can have unexpected and even bizarre
ramifications in code.  For instance,

$a = $b([0]);

would become perfectly legal syntax, and although it is pretty to those
of us who pine after ASCII art, its action is not as obvious as:

$a = $b(array(0));

This is just from a user perspective.

Now, from an internals perspective, taking a look inside
zend_languager_parser.y, currently, it is easy to tell when an array is
desired.  T_ARRAY always portends an array.  With the new syntax, this
is no longer as deterministic.  '[' is used for array initialization as
well as array access.  Seeing a '[' in isolation, it is not enough
information to know whether this is array creation or array access.  In
fact, as the example above shows, the identical syntax is valid for
creation [0] and access [0].  Even with careful attention to precedence
and ordering (does '[' bind to the right or the left side of the
expression?) it can be very easy to introduce bizarre parse or compile
errors.

Now, this may sound blunt, but the tone of your message suggests you
haven't worked much with parser generators or lexer generators in C.
They're one of the more quirky and finicky aspects of PHP internals, and
seemingly simple changes can result in ridiculously complex problems.

> I think a lot of web developers who use PHP would agree with Rasmus'
> sentiment[1]:
> 
> "What is clear and understandable to web developers is a moving target.
> As someone mentioned, nobody who does any sort of web development today
> can ignore Javascript and they will typically be switching back and
> forth between Javascript and PHP every couple of minutes.  This is our
> target user these days and as such this syntax is appropriate I think."
> 
> [1] http://marc.info/?l=php-internals&m=117060700805108&w=2

Having said all of the above caveats, I personally am on the fence
regarding the new syntax.  I was also confused when I first started
working with PHP about the use of array() for array creation, but this
lasted less than an hour, and then I was grateful for the simplicity.
Later I grew tired of typing "array", but I type pretty fast, so it's
not really an issue.

I am used to arrays, and find them intuitive.  I am a bit concerned
about code like this rearing its head:

if (1) {
    $a = [
        [
            ['a' => 1, 3],
            ($b = 3),
        ]
     ];
} else {
    $a = [
        [
            ['b' => 1, 3]
        ]
     ];
}

"bracket hell" is not something I've associated with PHP much, and the
new syntax would definitely make it possible, but would also simplify
the amount of spurious stuff on the screen for me in my work if used well.

So, I am +0.5 for [] syntax in principle.  I have not examined the patch.

Greg

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to