Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115682 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4701 invoked from network); 10 Aug 2021 07:29:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Aug 2021 07:29:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8ADA0180212 for ; Tue, 10 Aug 2021 00:59:44 -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-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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, 10 Aug 2021 00:59:43 -0700 (PDT) Received: by mail-lj1-f175.google.com with SMTP id m18so16454690ljo.1 for ; Tue, 10 Aug 2021 00:59:43 -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; bh=4iJDTKrI5eNH8whKhVcYx9vqZwWGUOSFaiSKZEIquls=; b=hlSr2lkmUvXySeGMRujzsc64qyAs6QtLutf/rGGrw9+HLQBwtInPXtnM0S6iz8x64p iuE3QwGA3wkiGoz4zGz5UNzIKEqIAFCNxiIyyvg27QsBDExAZpkUHacE3/oSCNofu92t 2+EPgz1ofcjfW67/ixFr1UDjZ6AoL0BXzhLcHlsyY3f9stEkKmifms5di0yBopIuBYs7 TFNHdePbDCJ6H/qQG7v52IdbfAOYJ/K5Rdlz+6qtx5rtqJep6tEqOqR9L0vRTCz4SkY0 95tehd1TYr07REnTWxtY0WxoLe9IhI7CuWzh7WM2fv/hHlWMuwTxTubyZqfTJSlbOATS +BTQ== 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; bh=4iJDTKrI5eNH8whKhVcYx9vqZwWGUOSFaiSKZEIquls=; b=qTIkSt+SNFzNH4+YhZQ5vmzFDaxwRozqcXeGZi6ENzRgOZxQ+q6LiDkYRKphm0Uynp io+Y6wdpSyBBfXwybIb12+oX3/PwjJrzTJzapSDGQu33UGY2KesIf3DEHNYt4h8p3fQB vA4nb+QDvcigjL8A9aRlTbDDBFv21sacXef9xIBV8kiroIHWp7c2z8VMmNFTrfAXL4xY nPuyhEukHOOHvEJvLm4DyWkgbdzJ7OJW/XL43BRzqoweHAwg0UQi6Iw4YeF70AHpuvwU JGswPdsqBBtx/QCF2GS1LjjOYv+OgNcXYXC4hwHD/Z/2za80GGOoDvVByMv1muTEFiSy u5kg== X-Gm-Message-State: AOAM532bzqf7drkT/U70z/POD1GWMkSufS48kVfCEp0DXDhbPQ6WdlBz 875QISLZtFC+9Of1obA1DTltS5RR6FEE36kqeNdlQRow1mM= X-Google-Smtp-Source: ABdhPJzNfuuSdSoECsqkoRC+OOfsG1d0cXovr6/CiejJ3UhQgEmDNrm5R2fcquKgvCkwC8gf8bcYWThLNlZueU35ACY= X-Received: by 2002:a2e:9e4a:: with SMTP id g10mr19226697ljk.54.1628582382047; Tue, 10 Aug 2021 00:59:42 -0700 (PDT) MIME-Version: 1.0 References: <94696d46-c4e6-406a-b859-89144bff31bf@www.fastmail.com> In-Reply-To: Date: Tue, 10 Aug 2021 00:59:42 -0700 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="0000000000005e94b105c92fe200" Subject: Re: [PHP-DEV] Revisiting Userland Operator Overloads From: jordan.ledoux@gmail.com (Jordan LeDoux) --0000000000005e94b105c92fe200 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Aug 10, 2021 at 12:15 AM Mike Schinkel wrote: > > So that gives me two (2) thoughts > > 1.) First is Geometry would be another area for PHP to consider adding > classes. > > 2.) Then I thought: What if PHP had the ability to explicitly define > *value* objects? I know this has been something Larry Garfield has > mentioned[1] in the past. > ... Can you see any reason why only allowing the addition of operator overloads > to *value* objects would too limiting? > > Hmmm. My immediate suspicion is that the technical details of how to make an object that *could* do this would be devilishly difficult. However, as an alternative to my proposal, it also has a year, so it's something we should explore. I think that if this were done very, very carefully, it would cover 80-90% of use cases, so it's worth exploring as part of my background and research for this RFC. > > =E2=80=A2 Length e.g. meters > =E2=80=A2 Time e.g. seconds > =E2=80=A2 Amount of substance e.g. moles > =E2=80=A2 Electric current e.g. amperes > =E2=80=A2 Temperature e.g. kelvin > =E2=80=A2 Luminous intensity e.g. candela > =E2=80=A2 Mass e.g. kilogram > > Those seem like a great *finite* list of fundamental units I would argue > PHP could benefit userland developers greatly by adding *standardized* > classes to handle them, maybe in a `PHP\Units` namespace. We already hav= e > Time. > > Then I can envision a `Value` base class, trait(s) and/or interfaces that > could support generic unit conversion that these specific units, like > Length. 1 'm' could be defined equal to 100 'cm' and then this could be > possible: > > Interesting! So the reason I actually started work on my math library was to support arbitrary precision math for my units/physics library, samsara/newton. I haven't updated it in about 8 years so it is... not a stellar example of the implementation, however handling this behavior is exactly what my library was for. There are at least two more: plane angle and solid angle. Plane angle is used in composition of units such as angular acceleration (plane angle / time^2), while solid angle is used in composition of the units for illumination (luminous intensity * solid angle / length^2). > > I'd argue for the shopping cart example it would make it more difficult t= o > reason about for the very reason that you gave three different potentials > for how to define a unit. > > As for Length being appropriate for operator overloading, absolutely. > > In a library situation yes, I was more talking in business solutions. Businesses that run their web application in PHP will build something that is obtuse to other people, because an individual business is usually obtuse to people who are not in that business. So I agree that you are correct, but I don't think there's any preventing that. That's just the nature of having millions of different programs written in the language IMO. > > However, that debate is a digression from our topic so we shouldn't > further it here. > > Fair. > > Unless adding those tools make it less capable at the tasks its best for. > And I am arguing that adding generic operator overloads for all classes m= ay > well make PHP less capable for those who want to write robust and reliabl= e > web applications. > > (If we add value object classes and add generic operator overloads there, > I feel much less concerned about PHP becoming less capable of achieving > robustness and reliability.) > > Ah, okay. This is the first clear articulation of *what* the issue might be. Now I will be able to investigate it properly, thank you. :) > > One final question. Let's assume that the functionality in your library > were to be added to PHP such that your library was no longer needed. Wou= ld > you be fine with that, or do would you prefer that features added to PHP > made your library more attractive as opposed to no longer needed? > > I'm not suggesting anything untoward =E2=80=94 it would be perfectly reas= onable > IMO for you wanting features to enhance your library vs. eliminate the ne= ed > for it =E2=80=94 I am just interested to know which avenue you would find= most > compelling? > > I wrote my math library because I found it necessary to support the units/physics library that I was writing and couldn't find an acceptable library for it. It was originally a means to an end. The units/physics library I originally started writing because I wanted to write a web-based game that people could play, and needed the units library for the kind of server simulation that I needed to run. I have actually multiple times considered translating my own math library to an extension or an RFC. I would have no issue with inclusions to core making my libraries obsolete. I've been working on them for 11 years and they are still not finished, it would be honestly amazing if PHP did support or had supported what I needed to do already. > > P.S. I've seen when language features are added that eliminate the need > for selected domain-specific libraries it can actually give the library > author room to provide even more specific functionality and increase the > library's value and thus increase the library's adoption, rather than > killing it. #fwiw > > I think this is likely the case with my library. I branched it out to add things like rounding modes, including things like stochastic rounding which are important for machine learning applications. I also added PHP implementations of statistics functions, since ext-stats has been abandoned for several years. If the core math was supported, I could probably focus on just providing the statistics module, or I could focus on extending bcmath that so that it supported trigonometry, or I could focus on many other aspects. I am unconcerned with the idea that core will make all my work obsolete because I am 100% certain that the amount of features I've written will never be included in core... the RFC to do so would be an endless stream of questions, the implementations would be complex and difficult for most people to reason about because they would require extremely strong algorithmic understanding *and* extremely strong math understanding. My library basically reimplements the entire PHP standard math library for arbitrary precision numbers, including all trig functions, hyperbolic trig functions, inverse trig functions, logs, euclidean coordinate systems... it would be like doubling the entire math library of PHP, which I highly doubt would ever pass a vote. Jordan --0000000000005e94b105c92fe200--