On Wed, May 20, 2020 at 12:07 PM Benjamin Eberlei <kont...@beberlei.de> wrote:
> the Attributes RFC was rather large already, so a few things were left > open or discussions during the vote have made us rethink a things. > > https://wiki.php.net/rfc/attribute_amendments > > These points are handled by the Amendments RFC to Attributes: > > 1. Proposing to add a grouped syntax <<Attr1, Attr2> Hi Benjamin, I find the grouped attribute proposal somewhat troubling. The RFC contains the following example: ```php <<Attr2("foo"), Attr2("bar")>> public function test() { } ``` The problem with this syntax is that adding a new attribute at the start or end of the list, or removing one of the attributes, will require modifying multiple lines. For some time the language has been moving away from this (see the various RFCs to allow trailing commas in more places), so this feels like a step backwards. If trailing commas are allowed in grouped attributes, you could write it this way instead: ```php << Attr2("foo"), Attr2("bar"), >> public function test() { } ``` But to me this still feels rather clunky. It requires two extra lines, and when moving from two attributes to one attribute (or vice versa), you'd still probably end up modifying multiple lines. Another issue with the grouped syntax is that comma separated attributes can be easy to confuse with comma separated attribute arguments. For example: ```php <<FooAttr(2 * 3 + 3), Bar(4 + 5 * 2)>> <<BarAttr(2 * (3 + 3), Baz, (4 + 5) * 2)>> function bar() {} ``` It can be hard to tell which line contains multiple attributes vs. multiple attribute arguments. Ultimately it seems like the grouped attribute proposal is attempting to work around the poor usability of the current verbose syntax. Maybe it would be better to instead propose a simpler syntax that avoids these issues. I know that some internals members expressed interest in an `@@` token, but this was never voted on. Having a distinct token for attributes would entirely avoid the issues of having to modify multiple lines when adding/removing attributes, as well as confusion with shift operators and comma-separated attribute arguments. E.g. the RFC example would look like this instead: ```php @@Attr2("foo") @@Attr2("bar") public function test() { } ``` To me this would be a lot cleaner and fit in better with the rest of the language. Best regards, Theodore -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php