Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111582 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 57977 invoked from network); 17 Aug 2020 14:18:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Aug 2020 14:18:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B9B04180089 for ; Mon, 17 Aug 2020 06:19:11 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 17 Aug 2020 06:19:11 -0700 (PDT) Received: by mail-lf1-f42.google.com with SMTP id c15so8354319lfi.3 for ; Mon, 17 Aug 2020 06:19:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nObQZMj+RM7TTIfB+FpGZCLDo0GhP+FyINLhmbt2x0A=; b=F2xOgPs6qOqNP5Qnv1E5asYmHBpeKn5PnWajywqLx85hX0pDP7M45YATKbc1gSdED6 aYw7MU2kKnAVUGNwNlsPQWAWTDhjJzbGqNvsYp6shronH2zHdEKuOu17TTKkNWloC1BJ plVAU8NUinkVrJ5aQ7dXZVc9Z/scMO/9HrLw9pUggIbRkcZePxPhRUvsg8b87BuH9LCI 10n5G86Zf29F1NHdejOwgTrJXkQ/nu8zMSXiygMmrvge6p5CP8DHKz3LkfTErpqI0OrK tAYmd4UPUmaKJ7cs4g+eYtG9WQoZvHjakSm7a/X7s+O84KS7NHKJcreom8/3tArQcVda ih9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nObQZMj+RM7TTIfB+FpGZCLDo0GhP+FyINLhmbt2x0A=; b=toTip3WZ3zpyb5XlrA2k1vYAAMogi3SVDv73kePI1YvBlxjsBjaNTmalsU87MS6OEE 2YzFD5X16HKMtQ05cIXHsCbs7OGav/gCgcKEm9JiQrGWP0enTC4N6xdaReWWYIx0Kn0I 6yeR+HoFhDrf+PFdBnaL+MESo3GZl/E3lTXL+3e0PPBTlNaeJ0beARB3pmfzpKHylBb9 7YVu64HDcZJaJyo5E+LHw9f14kvt/YWMRgpd88Kj7PcxxutVgYreTeYy5c4N48CkAumL c2j6AUSzJEiITVMbyncnTsC022zy/+T0zpCKX6CMpGDV50nJuR0w4pe58R/EAYzxqBJi QzWA== X-Gm-Message-State: AOAM5328Jmi5BTVws1Fr4XNecGfBVafs9qRPBXDKPj/IwP0Rmp/dV4Zm IkAlLyKDOSGCNpNJuYOOzeF4NFBXP7zZcPkZqew= X-Google-Smtp-Source: ABdhPJwjeOwgzwIoAfEmZWbjYZnYTOe0H18/Yo/F3m3/kqWWdbKWnvrvLjA38D1m8hks+X48nm6b2Ub9lbL04wJ+Q/c= X-Received: by 2002:a19:830a:: with SMTP id f10mr7436581lfd.28.1597670348577; Mon, 17 Aug 2020 06:19:08 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 17 Aug 2020 16:18:55 +0300 Message-ID: To: Theodore Brown Cc: Benjamin Eberlei , Derick Rethans , PHP Developers Mailing List Content-Type: multipart/alternative; boundary="00000000000098600305ad129d37" Subject: Re: [PHP-DEV] [RFC] Shorter Attribute Syntax Change RFC 0.2 From: benas.molis.iml@gmail.com (Benas IML) --00000000000098600305ad129d37 Content-Type: text/plain; charset="UTF-8" On Mon, Aug 17, 2020, 4:07 PM Theodore Brown wrote: > On Mon, Aug 17, 2020 at 7:11 AM Benjamin Eberlei > wrote: > > > On Mon, Aug 17, 2020 at 3:06 AM Theodore Brown > wrote: > > > However, ending delimiters in PHP have little to do with how "complex" > > > a syntax construct is (which is a rather loose definition, anyway). > > > As I've pointed out before, standalone statements and declarations > > > generally require an end symbol, but modifiers before a declaration > > > do not. Attributes fall into the latter category, and therefore the > > > lack of an end delimiter is consistent. > > > > A docblock is also a "modifier" under your declaration and it has an > > ending symbol. > > The difference is that a docblock comment is also a standalone > declaration - it's quite common to add one at the top of a file > that doesn't modify any other declaration. > Doesn't matter that you can add them anywhere. Internally, doc comments (on structural elements) are stored and handled by Reflection the same way that attributes are. > > The RFC gives a definition of the complexity as just a token vs a > > set of name, arugment_list and constant expression parser rules. It > > shows an example porting an ORM\JoinTable Attribute, which has > > arguments, named parameter usage, complex definitions of default > > values (Strings, arrays). > > > > This piece of code probably touches 10-20 parser rules. > > > > Most modifiers don't even have a parser rule, as they only match > > their token. > > In this comparison really the only "complex" part of an attribute is > the argument list, which already has its own start and end delimiters. > So I don't really see the need to add another end delimiter after the > argument list end delimiter > Again, in the future we might introduce a new feature that might make attributes have more complex parts than just an argument list. In this case, `@@` or `@:` is only going to f*** us up. > > Types are missing indeed, and they are more complex than a simple > > token, but less complex than attribute declarations. > > > > I guess the difference is that union types are new, and type > > definitions used to be simple. Attributes however are *new* and > > already complex, so we still have the option of always enclosing > > them. > > An attribute without arguments has essentially the same complexity > that a type declaration has always had. The only part that is more > complex is the optional argument list, which as stated before has > its own start/end delimiters. > > > > The RFC suggests a benefit of "Consistent colouring for being an > > > end of the attribute syntax and the keywords in between can use > > > different colors." I don't really understand this argument. How > > > would an end delimiter change the syntax highlighting provided by > > > IDEs? > > > > If you consider the three elements of an attribute declaration: > > 1. Syntax for Attributes 2. Atttribute Name 3. Arguments then if > > you color them in three different ways, then with an ending symbol > > it improves the human readability to have the end be in the same > > color [as] the beginning. > > I see what you mean now. Personally I don't think a differently > colored end bracket will be particularly helpful to readability, > though. IDEs will already highlight the argument list start/end > delimiters, and the different coloring of an attribute name from > whatever token follows it will ensure readability whether there is > an argument list or not. Ultimately perspectives on readability will > differ, though, since it's a somewhat subjective consideration. > > > > ## Potential Future Benefits of Enclosed Delimiter Syntax? > > > > > > The RFC shows an example of a potential "simpler" attribute using a > > > string instead of a class name. I honestly have no idea what this is > > > supposed to do or what benefit it would have over normal attributes. > > > > > > The concept of attributes being a class name with optional arguments > > > has been proven over many years by its use in docblock annotations, > > > and if there was some deficiency in what this syntax allows it seems > > > like we would have discovered it by now. > > > > I agree on just the string, but a closure would make 100% sense for > > a decorating feature. Javascript and Python "Attributes" work as > > decorators, i.e. they get called around the decorated function. > > > > It is not a completely unrealistic feature to think off: > > > > @[fn($x) => syslog(LOG_INFO, "Called function foo with x: " . $x)] > > function foo($message) {} > > As I understand it JavaScript decorators do not use anonymous > functions for decorators like this, though. Instead you would make a > named function and apply it with `@myFunc()` before the decorated > function or class. > > Presumably we could accomplish the same thing in PHP with e.g. an > `__invoke` method in the attribute class, without complicating the > attribute syntax itself. > Best regards, > Theodore > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --00000000000098600305ad129d37--