Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114186 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 37849 invoked from network); 26 Apr 2021 11:08:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Apr 2021 11:08:19 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 04A641804DB for ; Mon, 26 Apr 2021 04:12: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_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-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (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, 26 Apr 2021 04:12:19 -0700 (PDT) Received: by mail-oi1-f172.google.com with SMTP id z7so3863986oix.9 for ; Mon, 26 Apr 2021 04:12: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 :cc; bh=6y6DXiuNH2JaqCARFShWWFRkS6OYKQFX3Eyr6yqdjW0=; b=i78Y22bXWbAOPCJycNDiJB6mmf56xeAajXrYBL0ERbGxrwCGdOhUUkuiwP0dJUlJvz B72yGQvMwruT7MEjSw+hokzJz2XPX0QgS4cr/1M9HN1HEtYwxYXyoxUbwY37yW+R7q42 8m9nr0q1iiIE58Uv8UrANcg0mLml2t9HP3204tWp9st1cHzLms3RQqaGfQNVt3iqHQAW AvqGCqHkYBOx62YLv7wV1b+VdT5FCwiXE+V/S8LJ6M/ncXQBSCSEuhmleBP7jMT8R5h/ OLka3mDVjvIMHCfnLP6PfFBRRKi93csufosqN3aoqqUCM8n9GSRfmcELt0oBbn1t0uXP DcxQ== 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=6y6DXiuNH2JaqCARFShWWFRkS6OYKQFX3Eyr6yqdjW0=; b=eEoTeSgAvZOz54XPDQepBDG9RxxnT9YIuq6pm631dwi5dqjGGTxAPQZwNfm+maGkpX u/1d1SckCHPgL432zLT5HVjDxUWOawbrg+RUgDWe3VmOFbifRRAZm8yEKq9aO3iDZ6ww QDLZdIyhHmrxpwxrP3MW68KWU5LHc8ROGE/E4arKHbL0PY7jiCj1TqL7IRW6o5neBoaD 4L3wPtM0M4m3WpQ216T8xFXKPwYXM3mTFCkzLpelnFfzUmhrNfTAxbGePIa9S3jq4Tng zXQSnxxMd1Uicc7a2IgWrNDQfD35Ift0HUZNy/3/OTt1yEr/Vtm2z4pnfx05bDUc6OcE NnVw== X-Gm-Message-State: AOAM5324KS1EBucJfBPXCdbe/VR33/vRmt/iVswF4hV3azk+9+HvokAT vfOsW6RyPsMUKErawuF7daR0+l9efEASUJ44g484gCuHpGvnWA== X-Google-Smtp-Source: ABdhPJw7Tz5yn93IYmy3ci1n7IcNYt434n3aysSWkKolGsqZccDwrtH+z/QVv4x5tKoK0Drx2sf0/K+xAd+jLzf3eYs= X-Received: by 2002:aca:c395:: with SMTP id t143mr6295330oif.152.1619435538437; Mon, 26 Apr 2021 04:12:18 -0700 (PDT) MIME-Version: 1.0 References: <5b9f1500-615a-48f1-815f-1d48b327ef90@processus.org> <179049b1475.11134368b213512.254739612773841999@void.tn> In-Reply-To: Date: Mon, 26 Apr 2021 12:12:07 +0100 Message-ID: To: Christian Schneider Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000015c3905c0de3837" Subject: Re: [PHP-DEV] [RFC][Draft] Sealed Classes From: davidgebler@gmail.com (David Gebler) --000000000000015c3905c0de3837 Content-Type: text/plain; charset="UTF-8" Yes I agree Chris, this is the same kind of argument I am making. > Note that the *exact* same argument could be made for typing parameters. I can document via a docblock that I expect a given parameter to be a string, or a Request object, or whatever. "There is little to no benefit in expressing that through a new language construct rather than through existing constructs and design patterns." Yes and no. There is a critical difference between type checking and sealed - type checking can actually prevent and catch bugs in the form of objective logical errors (e.g. $total = getSum(1, 2, "not a number")) before they occur, whereas sealed can only prevent things you did not intend or foresee, without knowing anything about how I am using some code; there is no bug or logical error which the use of sealed will prevent *in and of itself*. > Except there very much is a benefit, for making the intent of code clearer and for allowing the engine to syntactically make certain invalid states impossible. This is not runtime benefit, it is runtime overhead. PHP cannot generate a better opcode sequence for knowing a class is sealed. In terms of implementation, the only thing it can do is scream "Hey! The author of this class didn't intend for you to use it this way!" - your IDE can do that from an attribute. And although I would say the claim no one will ever have a legitimate & good reason to extend some class and be able to do so in a way which does not violate whatever protections against invalid state you had in mind is a very bold prediction which is rarely borne out by reality - my objection here is not about people marking classes as sealed, it's that we don't need a new language construct and keyword to achieve the only benefit it delivers (declaration of intent to users and IDE). If PHP reasoned about classes in the same way compiled, statically typed languages do and therefore derived some tangible compile-time benefit from a sealed construct, I would be in favour of it. On Mon, 26 Apr 2021, 08:54 Christian Schneider, wrote: > Am 25.04.2021 um 05:47 schrieb Larry Garfield : > > In practice, I think all of the use cases for sealed classes are > ADT-esque. As I noted before, combining sealed classes with Nikita's > new-in-expressions RFC would allow for this (also using my short-functions > RFC for this example, although that's a nice-to-have): > > > > 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. Just > because *you* deemed that useless or wrong. > > I've encountered situations like this and came to the conclusion that > while this makes sense for languages like Haskell - where the whole idea is > to be able to reason about a complex type system - it is an anti-pattern > for other languages like PHP. > > Referring to another post, not yours: People, please don't use Java as a > reason to add something to PHP, Java is the king of anti-patterns ;-) > > - Chris > > --000000000000015c3905c0de3837--