Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114235 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36862 invoked from network); 28 Apr 2021 13:46:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Apr 2021 13:46:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 57E611804CC for ; Wed, 28 Apr 2021 06:51:22 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (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 ; Wed, 28 Apr 2021 06:51:21 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 1E9E6A3E for ; Wed, 28 Apr 2021 09:51:19 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Wed, 28 Apr 2021 09:51:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=WOMnVM yONfm1Aa0XdjPhZMwGPtOp8m/TB96Gn70LKwU=; b=i0b80z+nxEOwAVbc8t+kl8 v1UXftcu2B0uWTvYg1UDm0fURB/4ZfoRx71WmxtA+qeXmKedJOj687hCwA+SSOsR D3miTT/nFy3g0Xd0eLye8IpoucKsuS7ODfA5/SWG43imWTqfg/4rWyuPGbpd8G3p lMqa3lEw+Kt83lPikYuomQK5Vfbp+kMwqlxe06CYaOu1wQI+8Z2eiOF7VhxmIwrJ GOXzjJ5ktNApG+RAtuCHiomGO+rlf8Yku4lKW3HQYEXxVxnTGxt3csrbaufXeL43 op8jzLSHYicduAeGcYEIgH6u0Mz4GBAhG+m6pf5CRJCs2JOAUACrbCHVC1C1zd0g == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddvvddggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 600763A02D2; Wed, 28 Apr 2021 09:51:18 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-403-gbc3c488b23-fm-20210419.005-gbc3c488b Mime-Version: 1.0 Message-ID: <00f6b478-1be4-45de-8ced-5f5dd7fd99ef@www.fastmail.com> In-Reply-To: <89342DDE-5F0A-48F2-A7A7-7660FDD70EA4@cschneid.com> References: <5b9f1500-615a-48f1-815f-1d48b327ef90@processus.org> <179049b1475.11134368b213512.254739612773841999@void.tn> <722ed544-69e3-3be4-f828-185914617228@processus.org> <51fffd88-03c7-463d-a6d7-94c086cb5893@www.fastmail.com> <89342DDE-5F0A-48F2-A7A7-7660FDD70EA4@cschneid.com> Date: Wed, 28 Apr 2021 08:50:33 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC][Draft] Sealed Classes From: larry@garfieldtech.com ("Larry Garfield") On Wed, Apr 28, 2021, at 7:06 AM, Christian Schneider wrote: > Am 28.04.2021 um 01:00 schrieb Larry Garfield : > > However! Classic OOP design patterns are not all that PHP supports, and that's a good thing. The "class" construct, for better or worse, is the syntax for logic objects, value objects, data objects, and control flow objects (such as Maybe, Either, etc.), plus assorted other patterns that are not part of the classic OOP canon. But they're still good and useful patterns, and often a better model than classic OOP "polymorph all the things" approaches. > > > > If we were designing PHP from scratch today, I'd argue for having separate language constructs for funcy-syntax-closures (which is what service objects are), product types (structs, value objects, all the same thing), and control flow types. Many newer languages do differentiate those better. That's not where we are, though, so we're stuck with class being the uber-syntax for anything even slightly interesting from a type perspective. So be it, but it does lead to ample confusion about which use case you're talking about, especially when not everyone is familiar with all of the different, distinct use cases. > > > > See also: This thread. :-) > > > > Sealed classes are... not really useful at all for service object use cases. They are useful for product type and control flow type use cases. > > > ... and ... > > Am 28.04.2021 um 09:39 schrieb Pierre : > > Yeah, final is something, I originally come from the Java world 20 years back, and it never hit me as something terrible in PHP, on the contrary, I use it "per default" personally to promote composition over inheritance, but when I do that I mostly write interface and composition based APIs which much more flexibility than an open to extension design (TL;DR: I always give the user an escape route other than inheritance, and document it). > > Those are good points you are bringing up. > You're basically saying that classic OOP has outlived itself in many > cases - something I agree with - and we need the ability to use other > patterns. > > With that in mind I'm not sure if we really want to tack all this > functionality on to "class". > I think it would be better and less confusing to most developers if we > were to bite the bullet and try to do it right. > Especially since my impression is that we only need to tack it on to > "class" if there is urgency and personally I'm not feeling it. > But then again YMMV. > > You convinced me from a -1 to considering abstaining from the vote ;-) Ha! Progress. :-P As I've indicated before, there are two possible paths to an essentially similar end goal, both of which have RFCs written but no code written: Sealed classes and the ADTs proposal. Sealed classes is built on, well, classes. ADTs are build on enums, which in PHP are themselves built on classes. In practice, some languages do one, some do the other, and I think one or two may do both. For the use cases I can envision, I think either would work. Sealed classes would be a bit more flexible, while Enum-based ADTs would be more compact and convenient in the typical case. There's one or two use cases I'd like to be able to implement where ADTs would probably not be sufficient (state machines), but then Sealed classes would be annoyingly verbose in those cases, so... I'm still mostly open to either approach, and not convinced that we need both (though I could be convinced, potentially). In practice, I think I'm good with whichever one someone is able to get implemented first, which is always the hard part of any proposal. (Someone else, I forget who, suggested type aliasing as another solution, where you'd just have multiple classes and, in effect, type alias a union of those classes to a new name and tell people to use that. I like type aliases, but I'm not convinced that's a viable solution in this case. It's very round-about.) --Larry Garfield