Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120333 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 41609 invoked from network); 17 May 2023 22:36:13 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 May 2023 22:36:13 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 33E6E18053F for ; Wed, 17 May 2023 15:36:12 -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,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 17 May 2023 15:36:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1684362969; bh=QvnNXsGcmYVQ9VwRoyDX4i+1hhh6PopdkDd47oFjU2Q=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=PZPPv0xr+OhIr0+PDj70T6LbXLNw18lPK1UHupXx9+3pGIxaJ0TWRredNSLBzcWdl sigR+/iLTgZyRmRyOtZbQHqX0mEElkAOUg30sYMIWNab7s6LYNryIRmlLmJ7VO2k4l REC5gdPTWbDJp8lGUF+/y8aswXJ2ZTZ8EdDvqMOIYl1yeoT/NLo1TMkjb//O8Tiiy5 Uy0tLGvIqTq+MrtuAGMLundXmLAPu9mxjphF3rVCo7I8EK3EjzBEKK1CvqRf3PP1ha 0LGTYJYbgML8N5uMIO7huDNBxvJH/BzEc5hT9smTFtXgxxsrGMw+d8UozO61rEWWMG GsE32FR7CSVvQ== Message-ID: <8c6039e1-8b9d-e86b-a278-90cad5e41a75@bastelstu.be> Date: Thu, 18 May 2023 00:36:08 +0200 MIME-Version: 1.0 Content-Language: en-US To: Dan Ackroyd Cc: PHP internals References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] RFC [Discussion]: Marking overridden methods (#[\Override]) From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi On 5/16/23 18:17, Dan Ackroyd wrote: >> I'm now opening discussion for the RFC "Marking overridden methods (#[\Override])": > > This RFC is probably a good idea, even if the number of people who > will benefit from the behaviour in the engine might be quite low. My > guess is the number of people who will bother to write those > attributes, and who also won't bother to setup CI, is quite small. I would expect IDEs to provide "Quick Fix" actions to add the attribute where possible if the RFC passes. From what I'm seeing as not-a-Java-programmer, the @Override annotation in Java appears to be very commonly used. I certainly came across it when forced to use Java at university. With regard to usefulness for less-well tested and old codebases, I can only talk from my personal experience with such a codebase. Having the proposed attribute there would certainly have prevented some regressions. One specific example that comes to my mind is a class that wasn't final but also wasn't meant to be extended. During refactoring I inlined one simple method to improve readability. However that broke a child class that relied on that method being called to adjust the behavior. If the child class would have had the #[\Override] attribute on the method in question, the regression would have been immediately apparent, even without having automated tests covering the functionality. > But, this RFC another step forward from where we are, to having 'too > many' attributes/annotations, so I have a question. > > How do we stop prevent ourselves from copying the problems that Java > has made for itself? > > Or putting it another way, is it possible for us to set any guidelines > on what annotations are 'good' or 'bad' ? I believe I touched on that in the "Why an attribute and not a keyword?" section, because I assumed a question like this would come up. The attribute as-proposed would not have any runtime effect on the code and neither would it have an effect on the public API of the code that uses the attribute. It is purely an assistance to the reader of the code and could be stripped without changing anything. If having the attribute on a method would result in an error being emitted after the initial code-and-debug cycle then the attribute is merely pointing out a breaking change in a *different class*. This breaking change would also exist without the attribute. It would just be less obvious. As such I believe that on a scale from 'good' to 'bad' the attribute is very far in the direction of the 'good' end. It is certainly more 'good' than both AllowDynamicProperties (affects the public API) and SensitiveParameter (affects runtime behavior). The ReturnTypeWillChange attribute is just a hack that will go away in the future based on my understanding, so I won't put it on the scale. > I hope I am at least consistent with my concerns about annotations. > > Danack wrote in https://externals.io/message/114116#114196 >> >> I think I disagree with this very strongly, and plan* to vote against >> any RFC that embeds another language in annotations.** > >> https://blog.softwaremill.com/the-case-against-annotations-4b2fb170ed67 Thank you for the link to that article, that was an insightful read as someone who, as said above, was forced to Java, but didn't deep-dive it due to dislike. I'd like to point out that the article specifically calls out the @Override annotation as one of the "good" annotations in Java: > That’s not to say that annotations are not useful at all. There are some great use-cases. For example, the @Override and @FunctionalInterface annotations in Java or @tailrec in Scala. These are checked at compile-time and provide actionable value to the programmer. They don’t modify how the program behaves at run-time, and they don’t required any kind of container at run-time to fully utilise the annotated class or method. This assessment by the article's author appears to match my assessment from above. I also believe that #[\Override] falls into a similar category as a #[\Memoize] you mentioned in your "one asterisk" footnote of the linked email. Best regards Tim Düsterhus