Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114163 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53136 invoked from network); 25 Apr 2021 20:47:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Apr 2021 20:47:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3CEC31804BD for ; Sun, 25 Apr 2021 13:51:20 -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-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) (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 ; Sun, 25 Apr 2021 13:51:19 -0700 (PDT) Received: by mail-oo1-f44.google.com with SMTP id i9-20020a4ad0890000b02901efee2118aaso4251524oor.7 for ; Sun, 25 Apr 2021 13:51:19 -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; bh=6pLurfLT/ZsX/P7uVh2hQNnT3UvlaG4mRZXNV3YWTW8=; b=Hs6WjCDrWrvEK7Qld2L0Bnw0uNFqnsKSLlMwUcrvTZowFbXnqL9KScgaVKv0PA2cug Ow/RJXQ59h8lgGllcyam0Z4ww2j0CRjPpC18M0nyuuQWIyVN/tC28l7uUu2M+o39eG5y PU2/dN6bdfTYCzi6SUTAgn5Tpf7ve/aI8sodjllXxC74U12y6rZt6KyIi82fSYQk5ZlZ LgpR5pVd1rwkBim34FDG5cBmScr1N5dcH16H7gS9vdUVgySenGDoxyfW/PLufg8Ip9N+ zw0xgxd/cdTm5t1lwIHHMCf/FKhDAMbs7wwGAV0OLSW3ymb80f0G4HI0GrJX8DORE6PP Y5CA== 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; bh=6pLurfLT/ZsX/P7uVh2hQNnT3UvlaG4mRZXNV3YWTW8=; b=jZn8ZnjUBm9Uounv6fytq4ODFUUCqRzbmQq6ev5SgzDzYk09Rx8OhVYELRVo7Y0QFz a4oATnJh2tIHAaunoAALgb8nPUcAIk+FN2d6y8HDTNuM710yQCW33c13gA106HcwY6ph 9vtcSPG4rzlA69z2POfk8hL/xjXO5ujV1zuEwBKkbyuylZ5yGtxvN38sEVYBjy7T3XyI 8UrWfZRA65GeLBE8H9YFVfywRgyS0e7SeeWFzoI/WJLD/15tBKqwWCUJ2cJwtwqz55yW HGX++04pV97XKDr0xiaqOlVdOQaIDoVM0LxzG6sN9+13y38/1ISK+lDDNKsvprXnczH5 s3uw== X-Gm-Message-State: AOAM53301ZaYGUhHXEXd92CZvNg8kRfz99JV8p8DiJtfsE9BiyuJL9il Tjzn0vm52icroBgiZElCbh3miJjZFNBuQsBAW+louo/wR7U= X-Google-Smtp-Source: ABdhPJxK/dS5Aeo/ss5m/hQ6uLQTp9vwoahOjZp64tMZIvpg+xe+rEqY5RCpk+XqOnntPn24QpwGAccIYxcUjJb1N/M= X-Received: by 2002:a4a:e4c4:: with SMTP id w4mr10672944oov.68.1619383875487; Sun, 25 Apr 2021 13:51:15 -0700 (PDT) MIME-Version: 1.0 References: <5b9f1500-615a-48f1-815f-1d48b327ef90@processus.org> <179049b1475.11134368b213512.254739612773841999@void.tn> <0BF84585-DDC3-4B25-BFD2-D8B916D135EE@newclarity.net> In-Reply-To: Date: Sun, 25 Apr 2021 21:51:05 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000a749c905c0d23046" Subject: Re: [PHP-DEV] [RFC][Draft] Sealed Classes From: davidgebler@gmail.com (David Gebler) --000000000000a749c905c0d23046 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Apr 25, 2021 at 8:52 PM Mike Schinkel wrote: > > On Apr 25, 2021, at 1:52 PM, David Gebler wrote= : > > > > Still, all these problems are solved to the same degree if you add a > > #[Sealed] attribute to a class which has no functional impact. You have > > sufficiently indicated to any user that extending this class is not a > > designed feature and may cause backwards-incompatible breaks with futur= e > > releases - in a way that both a programmer and IDE can reason about, > which > > in PHP's context is what matters. Attributes arguably even have a great= er > > qualitative advantage that they can be applied right down as far as > > individual method parameters. > > In my experience, if a developer needs access to a feature that is easily > available via the use of a method that is merely documented as internal-u= se > only, the developer will use it rather anyway than spend a lot more time > trying to work around what that method makes easily available. Especiall= y > if that documented internal-use only is about not subclassing. > > And if many other developers do that, the original developer will still > have the same problem as if they didn't document it as internal-use only. > > But I do acknowledge your experience might be different. FWIW. > You're answering a different point to the one I'm making, which is that in contrast to a language like Java, where the compiler gets a benefit out of reasoning about virtual vs non-virtual methods, the use of sealed as a language construct in an interpreted language like PHP can do nothing which isn't already achieved by annotation - the expression of intent. > > > In Java the idea of final and sealed classes makes more sense, since we > > actually to some extent need the compiler to be able to reason about > these > > types and can gain optimization and code generation benefits from its > being > > able to do so. PHP's concept of typing and implementation of type > checking > > as an interpreted language is completely different. > > > > I wonder, if final and sealed as language constructs really offer the > > guarantees about intent and safety their advocates say they do, why are > > they not the default? Why can no one point me to a language where I hav= e > to > > write something like > > > > extendable class Foo permits all { .... } > > > > (and there are people who would be in favour of making inheritability > this > > explicit, but I'm not one of them) > > Well, I can't point you to a language that works that way because I don't > know more than a handful of languages in depth =E2=80=94 although there m= ay be one > =E2=80=94 but I can point you to a language that does not even allow you = to > subclass: Go. > > The Go designers wanted to get away from the fragile base class problem s= o > they provided embedding instead: > > > https://medium.com/@simplyianm/why-gos-structs-are-superior-to-class-base= d-inheritance-b661ba897c67 > > I program more in Go now than in PHP, and I can confirm that its approach > works brilliantly. Better IMO than what PHP currently offers in that > respect. > Again, this doesn't seem relevant to the discussion in respect of PHP or the RFC we're talking about. I don't have a Go background but I'm learning it at the moment and I like it a lot. Nonetheless it's neither comparable to PHP nor object oriented in a conventional sense so any direct comparison here is probably not too useful. > > > It's one thing as an author of code to say "I only intended and support > > this finite set of use-cases", it's quite another to say "and you shoul= d > be > > impeded from proceeding with any legitimate use-case I didn't imagine o= r > > foresee" > > I do respect that as a user of other developer's code you might view it > that way. > > But then I also can respect the library or framework developer who choose= s > to make their own job less difficult by (wanting to) mark a class to be > sealed. > > You claim "it's quite another thing to say" but I don't think a developer > of library or framework code should be required to offer features to thei= r > users they do not want to offer. It is the developer's prerogative; if > they want to be able to mark their classes as sealed they should be > empowered to do so. IMHO, anyway. > My argument is not that there aren't legitimate cases where you want to indicate a class or interface as sealed, nor that developers should not be empowered to make this indication. It is that in PHP, as an interpreted language, there is little to no benefit in expressing this through a new language construct than through existing constructs and design patterns. > > > In practice, the only thing I've ever seen this achieve is to create > > difficulties, while the claimed benefits can be adequately (and better) > > achieved through existing patterns like annotations, interfaces and DI. > > I would argue that maybe the reason you have only seen it create > difficulties is because of your own perspective and experiences that are, > by definition, anecdotal and thus limited. > > OTOH Fabien Potencier and/or Taylor Otwell might have a different > experiences and thus a different perspective on what those benefits are > (but I am admittedly just hypothesizing here.) > Allow me to re-phrase then, in a way which removes anecdotes from the equation; what is the problem in PHP which would be solved by adding the sealed keyword (or any equivalent) and can't be solved via attributes or other features already part of the language? There's no runtime benefit and an IDE can read attributes to tell you you're breaking someone else's intentions and prevent you making a mistake in respect of that. Part of the argument I see for these features in languages which have them is that inheritance is dangerous. And it certainly can be, but it can also be dangerous to put in new language features which can be misunderstood and used inappropriately. I just think we need to carefully weigh up the cost/benefit of new language features (particularly new syntax). > > -Mike > > --000000000000a749c905c0d23046--