Re: Re: [RFC] Attributes v2

From: Date: Fri, 17 Apr 2020 18:46:27 +0000
Subject: Re: Re: [RFC] Attributes v2
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-109698@lists.php.net to get a copy of this message
On Fri, Apr 17, 2020 at 12:43 PM Benjamin Eberlei <kontakt@beberlei.de> wrote: > On Fri, Apr 17, 2020 at 6:11 PM Theodore Brown <theodorejb@outlook.com> wrote: > > > Can you provide an example of an attribute name containing whitespace > > that would be allowed with the shift left/right tokens but not with the > > attribute token? > > This is about [whitespace] between token and attribute name, so > @:Foo > is allowed but @: Foo is not. Whereas with the hugging As, > <<Foo>> > and << Foo >> is allowed. Ah, that makes a lot more sense. Thanks for the clarification. I guess allowing whitespace could also be considered a downside, since it will lead to style guide wars about which spacing convention to use. > This is a personal assumption here, but I would assume 95% of developers > have never used >> or << before or for a long time and maybe 80% don't > even know what bit shift means and how it works. I would think nobody > needs this in attributes. Even if bit shifts are rarely used, the fact that such syntax is valid means there's a higher cognitive load when reading attributes to understand whether a shift token is part of a parameter value or delineating the start/end of an attribute declaration. Quick, does this function have two attributes with one parameter each, or one attribute with two parameters? ```php <<SomeAttribute(2 * 3 + 3)>><<Foo(4 + 5 * 2)>> function foo() {} ``` How about this one? ```php const Foo = 2; <<SomeAttribute(2 * (3 + 3)>>Foo, (4 + 5) * 2)>> function foo() {} ``` Even if the syntax is technically unambiguous, reusing shift tokens as attribute delineators results in symbol-heavy code which is harder to quickly and correctly understand. FWIW Hack is apparently moving away from the shift token attribute syntax to one using @ (see https://github.com/facebook/hhvm/commit/3983bd2ca6b252a93d98f2bb2d7e8e89f6f004d1); Sincerely, Theodore

« previous php.internals (#109698) next »