Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120781 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96636 invoked from network); 11 Jul 2023 17:42:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Jul 2023 17:42:48 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4040D180339 for ; Tue, 11 Jul 2023 10:42:48 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 11 Jul 2023 10:42:47 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 71A9F5C008E; Tue, 11 Jul 2023 13:42:47 -0400 (EDT) Received: from imap45 ([10.202.2.95]) by compute4.internal (MEProxy); Tue, 11 Jul 2023 13:42:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:cc:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1689097367; x=1689183767; bh=8JICYMRekLfbKQuLHG/D7Ztqsa9CZxf6FeS YOKl5D98=; b=wogKhI0ig5WIC/KfGMmSDsWwX9c/Dcl5djNxYqflu+6yxkrJ036 eB3nqzWeI+MCeKLSYIIluP3XZrI9qOFN/0AS9i7mUTRDRKIbzbfkCXpr1na+adHv OFVjm+Nha8AlLhVdwvBCJWQswKhfyl0HHj+PAiB/KAZY4IwqcL8KlxN9e5LQV8Wl hI1HEPB8sumYp6b4QwQcWIf+aEy6lT5nm5yj/+Z6CBqBXkBIvGi0SMIYNNqDpXJ3 gMzReCmZZmT09FW9Tup7q2xWLtYUPXzt3UNJ4KM0SouX7rHqpIAFi4IwoXzMpE8+ crW6npksGu1PBF19o1B11a6X+Ij9qaTZU3A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1689097367; x=1689183767; bh=8JICYMRekLfbK QuLHG/D7Ztqsa9CZxf6FeSYOKl5D98=; b=dNzZsz00RccVwq8tZ+2pntUw8URuv QA1PC14ZLm8JrqIxZ6edL4I881DNxJYtTQMbGTOK31uZ3XoEmhfLI4x02/GtQy0E HIrlODU757oZYtnQ56s7ism28gJ/zOk2476RDU+UmktDXaTwcFSzL7SsS4DsooqZ FYlXCtU4ylPz2Id+WrR37sXBLxU/8l2GPy+eQ8HsWnHjA7gBbkKntCB1o0WfD3Bk stOiYdwcV+Y8cXondUd3QpOkxk9IsccvhnutMa6FCuBp7wHhe2+fYPczppr9KxSh 1Qa0TVGJj5RASF2Bny5nbAehQsC8SViw57D5ZPv7vD1k2CsemVdpzYS0g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrfedtgdduudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepvdevteejtdefheevveegjeektdekgefgudfhudeh ieejfeetgffggeeghedvteevnecuffhomhgrihhnpehgihhthhhusgdrtghomhenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehg rghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 29371272007A; Tue, 11 Jul 2023 13:42:47 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-531-gfdfa13a06d-fm-20230703.001-gfdfa13a0 Mime-Version: 1.0 Message-ID: In-Reply-To: References: <3a3e7781-c2b4-2880-8048-d19458ac287d@heigl.org> <308d32d6-c145-4f8c-8779-101a696b60a0@app.fastmail.com> <66e67efa-1f41-4971-b070-7785f99ab286@app.fastmail.com> Date: Tue, 11 Jul 2023 17:42:26 +0000 To: "Robert Landers" Cc: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [VOTE] Interface Default Methods From: larry@garfieldtech.com ("Larry Garfield") On Tue, Jul 11, 2023, at 5:28 PM, Robert Landers wrote: >> Real code I wrote a week ago (specifically, for a series of events in a domain model): >> >> https://gist.github.com/Crell/f5929e2ee44decd4e9353c41874f26c8 >> >> Two different interfaces, that I want to be able to check against, but their implementations are trivial. One of them is used in 2 classes, the other in 3. A base class simply wouldn't work, both because it's semantically incorrect (these events are not all "special cases of" some common definition, that's not the data model), and because then I couldn't have the class that uses only one of them. Traits, for now, are the best solution, and this is an approach that gets taken a lot. > > Ah, I see. I would have simply created an ErrorResponseCarrier class, > then had PreRouting and PostRouting extend them and implement whatever > other interfaces they needed. > > IMHO, using a shared base class reflects the inheritance better > because they are siblings (at least these appear to be logical > siblings out of context, IMHO) and should look like siblings in a > class diagram. Their current dis-jointed-ness strikes me as odd and > the usage of traits in this way strikes me as an anti-pattern. But I > came from a PHP world where traits were nearly forbidden or used very > sparingly. Traits are a surgical tool with a narrow set of uses, and systems that over-use them cause problems. (You know which framework you are...) But this is one of their main valid uses. In context, the classes are not siblings, and it would be incorrect for them to extent from a base class. They just both happen to implement the same *interface*, but that the same as having the same "is a special case of" relationship with a base class. Having a common base class instead would, as noted before, mean as soon as I added a third "carries" option, I'd have to add four more base classes to cover all combinations. It quickly gets absurd, and those base classes have no valid type usage; they're purely there as an alternative to copy-paste. Using inheritance as an alternative to copy-paste is the wrong way(tm) to do it. Both inheritance and copy-paste. Freshman CS classes still love to talk about inheritance as a great thing for code reuse but... it's really not, and many of the 21st century languages have been drifting away from that. Traits/default-method-interfaces are a better alternative that doesn't conflate "copy-paste avoidance" with "is a special case of." Honestly, I almost never use class inheritance in my greenfield code these days. --Larry Garfield