Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117397 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60802 invoked from network); 22 Mar 2022 14:01:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Mar 2022 14:01:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4D3A218053B for ; Tue, 22 Mar 2022 08:28:10 -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=-1.6 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS16276 94.23.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (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, 22 Mar 2022 08:28:09 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id 6B77E5100319; Tue, 22 Mar 2022 15:28:06 +0000 (UTC) Message-ID: <841033de-3b13-8022-98dd-a577dd08790b@processus.org> Date: Tue, 22 Mar 2022 16:28:05 +0100 MIME-Version: 1.0 Content-Language: en-US To: Sara Golemon , Robert Landers Cc: =?UTF-8?Q?Micha=c5=82_Marcin_Brzuchalski?= , Larry Garfield , php internals References: <1289b56c-e766-4889-bbb2-06abb4e63a6d@www.fastmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Re: [PHP-DEV] Discussion: String streams From: pierre-php@processus.org (Pierre) Le 22/03/2022 à 16:14, Sara Golemon a écrit : > On Tue, Mar 22, 2022 at 5:38 AM Robert Landers > wrote: > >> But why can't we have generic operator overloading in which case this could >> be completely built by libraries in userland? >> > I mean... honestly, I feel like I come back around to this very quickly. > Generic overloading gives us much more at the end of the day and allows the > people using PHP day in and day out to make the actual decisions about what > any of these APIs should look like. > > So while I said I wanted to avoid the firestorm suggesting userspace > overloading would bring, maybe that's the question to ask: > > Who's just a hard-nope on userspace operator overloading? If your reasons > go beyond foot-gun (and that is a valid reason), could you share what those > reasons are? > > -Sara Hello, I am a not so hard-nope against userland operator overloading because it's magic. My day job is 20% writing code, 30% speaking with clients, and 50% reading and using community code. Userland operators are not as explicit as verbose method calls; and you can't ctrl-space an operator in any existing IDE, it's not obvious at what they does when you read code using them in most cases, and beyond that, in order to use them, you have to read an external documentation. Not that I don't read external documentation, but 80% of time, reading directly interfaces in my IDE is enough to know what to do with an API. When an API uses methods for doing stuff, code is auto-documented, when people start overriding operator, not so much (at least not as easy to find and understand at first sight) especially if the code is segregated behind interfaces and those interfaces don't explicit the operators (At least I hope that, if userland operators land, that interfaces will have a way to explicit the override). And in the end, operators are just sugar for method calls. I don't dislike writing $c = $a->plus($b) instead of $c = $a + $b, I even found that there's some kind of elegance behind writing stuff explicitly. There's no feature in the world that would be blocked by the lack of operator overloading. Moreover, the << >> c++ style stream operators are no more than a way to implement the string builder pattern, if I understand it well. Then why can't simply we use a StringBuilder class and use methods such as append(), prepend() and all ? It's much more explicit and much less alien-like for most people. Regards, -- Pierre