Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114205 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 99191 invoked from network); 27 Apr 2021 16:53:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Apr 2021 16:53:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 72DE81804DF for ; Tue, 27 Apr 2021 09:57:47 -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-vk1-f182.google.com (mail-vk1-f182.google.com [209.85.221.182]) (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:57:47 -0700 (PDT) Received: by mail-vk1-f182.google.com with SMTP id o17so13071187vko.8 for ; Tue, 27 Apr 2021 09:57:47 -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=1lvAM4yWvsk4Ob1atvju0ZFjGlGUtYawwqbv+2Ljrzw=; b=ZH70yR7wva1inytB7wkl5xdC5StlSVUYcK/ZgHtgXX5uM3GZ6vzVrJxQtLus+gXXSX Q3Ajve9WwrRki8gLbOHl6+27/eGZJT3gUHZEHOodKy/GTPnKYUf9sHUqzuDcyRrjr/sH 9wAkA1gZWqo4v52udbxiFKT1JWwsyLhzJROnrRLZYfqNIVYRxY4hh2EC0/RQZZraKU/c RTQriewNT2iGnV+Dp5L0D3dcgx3vHY7rKnML9wF4u4vj4QqtFmQQKBOfFGI8S/O72xnU bhRhPO/6JEZm685syZzvEYACE9k7FVoiJ4sx7YQrFsFxMIhlkR5CC6Jul3+iP5ZB11oL t1kw== 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=1lvAM4yWvsk4Ob1atvju0ZFjGlGUtYawwqbv+2Ljrzw=; b=lHqCTsVjvV7EJgu/hhZjCqQRYtyzBehn8jme5xK/897xz2El0Po+SoTVoaiosHpMpm 7XDR8x7wxpiGJeFdYxrn3FPDgKoyG4NtP7KjVtnIW8NNWZiJ38d59dzSiPFP1LJVBH5q Z6cFW0CuNd8k6+Ir7Xj4+KwvH9jmGOgwudmgtSBvMy+16zExUMm5B7LAcbmAPCidMALy mBDB8m85oXMMU23gybYshOBudU8Yp/l+emNUg+IG27iCL8LQEKtIFHjkomDbWhDB421W Kt6chHUgJn+s1Fa5ImlNuWO8kG9nusw9lf/oWXv6ETxKJOw8Oin8moX6+LgqJiBq58h+ jjBQ== X-Gm-Message-State: AOAM533q+taujYHHyVfTQCNNUgjMh7LcFqHoklf163yox3rmi81r3kua 0kw+fn4/UQe3fkFqcW80z2dSnLpfT5F2B3KN8hw= X-Google-Smtp-Source: ABdhPJwV2afephG15vIqQHBWFkTS8XNAUeOYJaqgdQH/Xx9Xrb+FUo4foRskmBLRh+EuES9jLSts5zBzaBgBl8oY648= X-Received: by 2002:a1f:3d46:: with SMTP id k67mr6499473vka.16.1619542663319; Tue, 27 Apr 2021 09:57:43 -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 12:57:32 -0400 Message-ID: To: David Gebler Cc: Guilliam Xavier , Christian Schneider , PHP Internals Content-Type: multipart/alternative; boundary="00000000000025528605c0f72969" Subject: Re: [PHP-DEV] [RFC][Draft] Sealed Classes From: chasepeeler@gmail.com (Chase Peeler) --00000000000025528605c0f72969 Content-Type: text/plain; charset="UTF-8" On Tue, Apr 27, 2021 at 12:47 PM David Gebler wrote: > 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. > > > I totally agree with everything said above. I will add that while I don't support the idea of sealed classes in any way, were it to be implemented, I agree that implementing it via compiler/engine enforced attributes is not the way to do it, echoing Dan's reasoning from earlier. > > On Tue, 27 Apr 2021, 16:05 Guilliam Xavier, > wrote: > > > Hi, > > > > On Mon, Apr 26, 2021 at 9:54 AM Christian Schneider < > cschneid@cschneid.com > > > > > 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 > > > -- Chase Peeler chasepeeler@gmail.com --00000000000025528605c0f72969--