Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114204 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96832 invoked from network); 27 Apr 2021 16:42:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Apr 2021 16:42:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 73C871804DD for ; Tue, 27 Apr 2021 09:47:13 -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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (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 ; Tue, 27 Apr 2021 09:47:13 -0700 (PDT) Received: by mail-ot1-f50.google.com with SMTP id d3-20020a9d29030000b029027e8019067fso53977881otb.13 for ; Tue, 27 Apr 2021 09:47:13 -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=6LyAbBYpGzYtN37FwDuCNTasUhzcMKbPoCbRZdZ/J5A=; b=Qr2qwpq4W7JFa4F4NOoUk37+vWFTSwJNmmqtkyVnFTUuWGURmUJ+QpAFkH7Q+1r61J cnjBk0jVH1e1TBsopi3uvt6PJZIDIl9hR5rrvOl0J8cmXH6tWlr1IVa4C0ruA4Ea5M8G G907iFTHCfreRQHgm4lISWDgPw0BuwvdgTwjo68stojg7dUt/ZR7Bwx251f85o47IbTV JOuP50qADQgLlKPvJ9P8swiWEIS02BIvL9cJeXUjN/FQqXBkXWNGcF7XH1GvcdYsTeZ9 wprYIJ5hVMUl6D2d6KeBAQXLg4PFw/Dp0NoALs9VqGMtS40CFKitSg3udKLMzL3Amc3q NBFg== 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=6LyAbBYpGzYtN37FwDuCNTasUhzcMKbPoCbRZdZ/J5A=; b=ne3ar1eBhPK2gCLsHapYbeskg+hX4Exl8IskQLeTvf3kAcnf1nFGQp+9bD5M4GYo3s DaoiHEkDRo2tF1n0TBiUdAtDB3QL5Jxfia548wCoQ5GIVxxu7t1KQ5CLm6Kv+PuUQG2t g+01q1hBUfRIa28a1KC+4PjC5Oetunb3ysQZ1GPfhdAJs5QlYzlmkayc6lZ+tvu74kWu 8CZpvR6Hu7SaOvQux5LSl7Gq5WLkvPwxoaolZnbQz8faIDx39TPFoS3uGPjUemIc51mv RJ9CgyQPV6KyVj2THbELJpTb8qOsbpMbNWMzaWJeQ3Xzm0MFZlSLKcrZcQ3HUg+fjf9N +6iQ== X-Gm-Message-State: AOAM530JgeVN6R2oS0y2IMLW9hR/Eqr4vjcuKDJ1AJkmFSE/YUT8+zAY khouI+v+LrZ2kUHVghYPppZBuxmueyZuALPOxnA= X-Google-Smtp-Source: ABdhPJwxIxreNEzGn/mhR6JkOt5vX3GZD8CxBCrYZO9q2FymTgfSy7TA9HrtBWTTZ0b0k10DIaT1+5LyPm9fNKoZyPs= X-Received: by 2002:a9d:1ea9:: with SMTP id n38mr20846701otn.233.1619542032320; Tue, 27 Apr 2021 09:47:12 -0700 (PDT) MIME-Version: 1.0 References: <5b9f1500-615a-48f1-815f-1d48b327ef90@processus.org> <179049b1475.11134368b213512.254739612773841999@void.tn> In-Reply-To: Date: Tue, 27 Apr 2021 17:46:59 +0100 Message-ID: To: Guilliam Xavier Cc: Christian Schneider , PHP Internals Content-Type: multipart/alternative; boundary="000000000000890d3105c0f703c2" Subject: Re: [PHP-DEV] [RFC][Draft] Sealed Classes From: davidgebler@gmail.com (David Gebler) --000000000000890d3105c0f703c2 Content-Type: text/plain; charset="UTF-8" Still, it remains that one could have a legitimate, justifiable reason to extend Maybe / some other example, which was not foreseen by its author and is prevented by sealed as a keyword despite the fact this inheritance, correctly implemented, would not break anything, not define an impossible state and not violate anything except the library author's own (limited) imagination of how their code ought to be used. Note in respect of the point people have raised about attributes and my own previous comments, I am not advocating any Sealed attribute is added to the language as a functional change or embedded language by the backdoor, I am merely saying *you* as some class's author can add an attribute, right now, to indicate that you consider the class sealed - and an IDE / automated tooling could understand it and warn a user there is a risk to violating it. What's being proposed in the RFC is a functional change to the language whereby attempting to extend a class designated as sealed to a non-specified child results in a fatal error. Now that is not a benefit in itself, it is merely a description of the proposed change. My question is who or what benefits from this change? And I look at this way: 1. The language engine doesn't benefit, since unlike some compiled languages, there is no indication here it will result in improved opcode sequences. 2. The author of code doesn't benefit, to any extent greater than they would by using an attribute or other metadata to indicate their intentions, because if someone else comes along, installs their library and creates problems for themselves by extending some concrete type in a manner which was not intended, the author's obligation to them is zero. If improperly inheriting or otherwise misusing code creates a problem for a consumer, it's the consumer's mess to sort out. 3. The consumer of code doesn't benefit, because if they didn't intend to inherit from a sealed, concrete class, it being sealed makes no difference. But if they did - and had a legitimate reason to do so - they are now forced to fork, proxy or otherwise work around this artificial restriction (which they can easily do, by the way, language keyword or none). In any valid use case, this can distinctly and only be a disadvantage to them. Someone - Larry I think - said something to the effect of this isn't about restricting your users as an author from doing something you think they shouldn't, and that it's about more completely defining problem spaces at language level. I respectfully am not convinced. When we look at features like enums and stronger typing, we can see distinct benefits in how as users of PHP we can model better and write better, more effective and more efficient code. But in the case of sealed and the context of PHP, you cannot model your problem space this way better than you can with an attribute or other means of annotating metadata. I can certainly agree such metadata is an important part and valuable tool for improved modeling, but making it a keyword and throwing a fatal error if your limited intentions (which do not predict all possible use cases) are violated is merely constraining users from being able to do something for its own sake. While there is a legitimate argument that serves to "syntactically make certain invalid states impossible", it does the same for any valid states you didn't envision. I'm maybe even inclined to suggest the desire to make a class sealed really smells like you want to be using abstract classes and/or interfaces. To the greatest extent which is practical, my preference is to enable other developers rather than constrain them (subject to the caveat I will not help them if they do something silly or irresponsible with my code on their own volition) - I don't believe the "weirdness" exceptions PHP makes internally for things like Throwable or Traversable are good reasons to extend this to the language level. On Tue, 27 Apr 2021, 16:05 Guilliam Xavier, wrote: > Hi, > > On Mon, Apr 26, 2021 at 9:54 AM Christian Schneider > > wrote: > > > Am 25.04.2021 um 05:47 schrieb Larry Garfield : > > ... > > > sealed class Maybe permits Some, None { > > ... > > > } > > > > > > final class None extends Maybe {} > > > > This is exactly the thing I'm worried about. > > > > Say I want to add something like logging to the None type. > > Now your sealed and final classes prevent me from defining MyNone > > extending None even though it would be 100% compatible with None. > > > > I just want to note that this has nothing to do with Maybe made sealed > (which seems legit), only with None made final (which... could be debated, > but unrelated to the RFC at hand). > > Regards, > > -- > Guilliam Xavier > --000000000000890d3105c0f703c2--