Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115665 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36777 invoked from network); 8 Aug 2021 10:55:50 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Aug 2021 10:55:50 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AA0611804C8 for ; Sun, 8 Aug 2021 04:25: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.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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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, 8 Aug 2021 04:25:48 -0700 (PDT) Received: by mail-lf1-f42.google.com with SMTP id u3so27911455lff.9 for ; Sun, 08 Aug 2021 04:25:48 -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=8kTRPL9cQu8OsvGnL3zCHASgZEkM3vK/E3UxMhubIyw=; b=uc3XfXtb1w/azoltXtZtdB+bsOxjVDxZRdKXextfa+2Hehb/Uc9yz1JN1S3dBCAbGs vlLdbjFNvssI6tjU47u9NVkiHmgGKrv1EQ8CydAPHPvsTdC3xuz4sSBj+e++aeVDVbON +xvcUgeQUpoRgj6FtyOY4pLPpZSTsudQ8g/EDTsXyWEhJnWfPE5+79ExSGpTazjZy2i4 iihdApp/kZ0x2uiC8cENI7ho4ByhL/0yNzo1E23EunP0/aYuvK/7rWfreYjzBcz7bjQo PYEpjYsPAIysr/7nPco7deOwdLXnfPSGNCeBhFg3ovVlH5aklFOEIlkGTgzXTAbHcXTk ogkg== 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=8kTRPL9cQu8OsvGnL3zCHASgZEkM3vK/E3UxMhubIyw=; b=boNJfxxOBQ+LBd6m4RLOWIgFfkxWpNEredxUqLDO3eusssyUl9xADSZAxUlruuHUsC a+02mLBedLNCpoXAfE8M4gq0ROdQey1J20hPJVjS5Jen93FID4ZoKf9lel4XGQUcy3nN RZsflrngFBydevD5cqZP5TbDZMvmQr3+GpSxmrk1/cKjBcob6nSKyiVjADz9wY+h5KCb +rFv4rF3WPTThImTpMvfuCQ2EYsaioPhZdoUsDJqRT9kBhWpPQUhUaNGMTrvCB/8FPIA MWg/u+q1NJImqzr/5noi5Z8Aq++501tbovDJfP6s8qD5hPSWcMRbdqvyaDO6kSefLpW5 Asbw== X-Gm-Message-State: AOAM532fMbbzhoecthssABWdcjUcHIWac1npE8bwWvx2TclLAp2z9P03 L/s0NGEpIx9P1JMONE+AdAVHvhhDBzIeuE/0/Jc= X-Google-Smtp-Source: ABdhPJw9av80sirk6PcaeOvY3pmjFccwWsxtS+NwAGyZZYbdhZDw4CSKkq1dQ2eSzjASyN7QwFTjM8x6QpzmwCCWJPY= X-Received: by 2002:a05:6512:16a0:: with SMTP id bu32mr6538231lfb.322.1628421944472; Sun, 08 Aug 2021 04:25:44 -0700 (PDT) MIME-Version: 1.0 References: <94696d46-c4e6-406a-b859-89144bff31bf@www.fastmail.com> In-Reply-To: Date: Sun, 8 Aug 2021 04:25:46 -0700 Message-ID: To: Deleu Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000008b78b305c90a87a6" Subject: Re: [PHP-DEV] Revisiting Userland Operator Overloads From: jordan.ledoux@gmail.com (Jordan LeDoux) --0000000000008b78b305c90a87a6 Content-Type: text/plain; charset="UTF-8" On Sun, Aug 8, 2021 at 3:08 AM Deleu wrote: > I started reading this thread with a total bias against it and as I read > through it I can only imagine how painful and annoying it is to maintain a > math library in PHP. Operator Overloading is truly a marvelous piece of > functionality for that domain. > > However my biased still exists: it would be awful to have to understand > what `+` is doing for every file of every library or even different objects > in the same project. > May I ask why? Python does not get much criticism that I can find for its implementation of operator overloading. Its implementation of operator overloading is very widely used in the language and is also not seen as a major source of "suck" for lack of a better term. Python allows virtually all operators to be overloaded, and takes the unique approach of having an add() method for when the object is on the left and radd() for when the object is on the right, with precedence always going to the leftmost object. There are many languages that provide operator overloading, and I've never seen it described as a bad feature in any of them. I've seen criticisms of the particular way it was implemented in a few, but not for the feature itself. I obviously understand the possible problems that could come from it. I work in PHP every day at work on a codebase that was originally written 11 years ago and has been maintained, updated, and added to. We run it on 7.4 now, and every year we have all the devs in the company spend time on migrating to the next PHP version. In such a codebase, I'm well aware of what kind of problems I *might* have encountered with operator overloading. But these don't seem to be major sources of problems in most other languages. Python even has multiple *default* overloads. # prints 12 print(4 * 3) # prints PythonPythonPython print("Python" * 3) So while I'm aware of the concerns, I'm unconvinced they are founded in reality. That is, I think the concerns about maintainability and complexity may be unfounded in real world scenarios. However it is an extremely consistent opinion here, and I would like to understand *why* it is viewed as bad for the language in a more concrete way if that is possible. > It's been nearly a decade since I part ways with Math, but if I'm not mistaken we can tackle most (all?) of the operator overloading with 2 classes: Number and NumberCollection (for lack of genetics). > Everything in math can programmatically be represented as these two *abstract* classes. This would very heavily depend on how broad they were. For instance, while complex numbers and fractions are both numbers, they would not implement all of the same operator overrides most likely. I think this is a workable solution, in that it would give the core feature in a way that can be muddled through to math-domain applications. However, I won't be doing that in my RFC. Not so much because I think it is an untennable solution for math (although it would indeed be FAR more complex of a solution from an RFC standpoint that directly allowing operator overrides). Instead, the reason that I won't be doing that in my RFC is that I would no longer want it to be accepted. If I wrote that in my RFC just to get the overrides that benefited the work I do, primarily around math, accepted into core, it would virtually guarantee that actual operator overrides would never come for other types of applications. Every future RFC on this topic would be riddled with comments about the existing abstract classes, and how all future implementations have to be done in a similar way. This would artificially increase the barrier to acceptance for other domains in a way that I do not believe improves the language, serves the users of the language, or allows for flexible development of the language into the future. So while I acknowledge that it may be a good middle ground (and even one that I personally would accept for my own implementations and code), I am unwilling to be the person that locks everyone *else* out of this language feature by making future RFCs more constrained and difficult to pass. I constrained this RFC to math operators not because it's the only domain that would benefit, but because I think it's the one with the most straightforward and understandable domain uses for everyone on this list and represents the "minimum" version of the feature. Jordan --0000000000008b78b305c90a87a6--