Re: [RFC] Shorter Attribute Syntax Change RFC 0.2
| From: | Theodore Brown | Date: | Fri, 07 Aug 2020 21:50:00 +0000 |
| Subject: | Re: [RFC] Shorter Attribute Syntax Change RFC 0.2 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-111369@lists.php.net to get a copy of this message | ||
On Fri, Aug 7, 2020 at 6:03 AM Derick Rethans <derick@php.net> wrote:
> On Fri, 7 Aug 2020, Theodore Brown wrote:
>
> > Even if we assume the implementation is only about 30 lines, it's
> > still extra complexity that I don't understand the benefit of. I
> > sincerely would like to know what advantage there is of grouped
> > attributes over the
@@ syntax.
>
> It was very *specifically* voted for:
>
> https://wiki.php.net/rfc/attribute_amendments#group_statement_for_attributes
Hi Derick,
It was specifically voted for the <<>> syntax, with the explicit
qualification that "This feature would be superseded by any other RFC
getting accepted that changes the syntax." This is exactly what
happened when the Shorter Attribute Syntax RFC was accepted.
> You still haven't addressed any of the deficiencies that the other
> alternatives don't have:
> https://wiki.php.net/rfc/shorter_attribute_syntax_change#proposal¯Ñ
> ¼cœÀ™ý(/ÓøNÄ
I'm not sure which deficiencies you mean, but let's briefly go
through the table in the RFC to make sure nothing has been missed:
- Number of required Characters:
- @@ has the advantage here.
- Has End Delimiter:
- This isn't clearly a pro or a con in itself.
- Allows Grouping:
- As discussed before, @@ has the advantage of being equally
concise without this added complexity.
- Forward Compatibility in PHP 7:
- This is at best a temporary benefit of #[] which will be
irrelevant in a few years, at worst a source of confusion and bugs
when code intended for PHP 8 runs on PHP 7 with different results.
- Breaks BC of valid PHP 7 code:
- All syntaxes but <<>> technically have a BC break. There really
should be a separate line in the table for "Breaks useful syntax",
since #[] and @[] have this deficiency, but @@ does not.
- Used by other language:
- This is listed as an advantage for #[] and <<>>.
However, the table
fails to point out that Hack is migrating away from <<>> to
@Attr.
Furthermore, while #[] has the same start/end symbols as Rust, the rest
of the grammar/semantics vary significantly. E.g. these are valid Rust
attributes (see https://doc.rust-lang.org/reference/attributes.html):
#[rustfmt::skip]
struct S {}
#[clippy::cyclomatic_complexity = "100"]
pub fn f() {}
This is quite different from PHP's semantics, so it's not clear that
copying the same start/end symbol would really be a benefit for us.
Also note that unlike PHP, # does not start a comment in Rust.
- Familiar with Docblock Usage:
- @@ has the advantage here once more.
- Tokens used:
- This isn't clearly a pro or con in itself.
- Changes the lexing of **remaining** tokens:
- This is apparently a con for #[].
Ultimately I think @@ does the best job balancing a very small BC
break with concise, familiar syntax that can cleanly support nested
attributes in the future. And since it avoids the need for attribute
grouping it also has the simplest implementation.
Kind regards,
Theodore