Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116799 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55789 invoked from network); 4 Jan 2022 01:58:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Jan 2022 01:58:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F24A41804B1 for ; Mon, 3 Jan 2022 19:06:01 -0800 (PST) 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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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-ua1-f42.google.com (mail-ua1-f42.google.com [209.85.222.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 ; Mon, 3 Jan 2022 19:06:01 -0800 (PST) Received: by mail-ua1-f42.google.com with SMTP id r15so60925548uao.3 for ; Mon, 03 Jan 2022 19:06:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=w0x/YUgvf2f3eSJBxAg8uKzGtCdw6hsdYpIrJ97gIxk=; b=T0k2JwI4fcvUwGavF7NkkR2pTiRJ9VobRpyKyEPT+hbUFUnnDeaABYr8I5nvOFO6Ds swd0M07uEVpiCejab93PsZ+f5P0K9lQ/2UstjkTRK7lNHEtAEpCHC+j5lEziSNxpaOsG II+VGZdHgAxTzzTL6TrmVvGChL9hFae+T4jfIYAyeRnrN19/nthiK5TT1yHm+OtyO0XT ZGBtKP1yU5qukThFIFFN7LeqACAwt89GQ2eomoLwUg2JR0YX0OgrgdsNkgNCsnYDBhyR 0jvxWr0TFcOElZbYjBrcIBMLE6EkAwL1ikYPqM1e8uzeviabPjqsv04ArU9G1NBOKG68 QAEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=w0x/YUgvf2f3eSJBxAg8uKzGtCdw6hsdYpIrJ97gIxk=; b=ExiYV55yjZ83gJFIbAWPwoYSHdWRJCKXG2iueCh2B3Q3I0wPP9y5TvAV0WAbp8QNKT 7DCNgOLSh9zijEMJcAojflj+SpcEGfWpD2G1tzJJkF7An+KBdjLSMfEXlLsbHECD/sDe 3ZmpZTAs1FtpI5/eX6fUwtKQjEfbi1ly8ardriU2ITAHuXnQVY6leAdeHEJQafYE6CKR PF8RjYe7uckNtbtKDx9UevNd4AK7QTqBKhI/GMI8K5DkRBJgnkj3Ss5YmCDDAMYU1pTx U1PdYSr/Ivf9ykTm1AvX5ScxF37t9OzQi/et4mx1Vb92IOUuq7DL9Ws95xQZdEZGBpab ictg== X-Gm-Message-State: AOAM5316drVM3BU0gu9wlWYf8xiSTHABRfwAAQUkRumGWl2cgeV3/h9j UZXBQaa3INrp0hI+mzipa3OUJKOg18fgwXqpito2lg== X-Google-Smtp-Source: ABdhPJywmxjXNjYgtyyf9ugnqn3dJYWr2qz1Naag05QWqMeizqx9UAwCuYIFwQW7Nk/QjExDV/weHY3hiJrEGXfibsA= X-Received: by 2002:ab0:525:: with SMTP id 34mr4185030uax.136.1641265560617; Mon, 03 Jan 2022 19:06:00 -0800 (PST) MIME-Version: 1.0 References: <3225c921-9b26-d2e0-f76f-45fff6f5a12a@processus.org> <40a1e5fa-396d-d9ef-93ab-6fcfb5054092@processus.org> In-Reply-To: Date: Tue, 4 Jan 2022 04:05:49 +0100 Message-ID: To: Jordan LeDoux Cc: Pierre , Larry Garfield , php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE] User Defined Operator Overloads From: andreas@dqxtech.net (Andreas Hennings) On Tue, 4 Jan 2022 at 03:23, Jordan LeDoux wrote: > > > > On Mon, Jan 3, 2022 at 4:05 PM Andreas Hennings wro= te: >> >> To me it is not surprising that an RFC like this would be controversial. >> We could enter a wonderful new era of value objects with operators, >> but it is hard to envision that beforehand. >> >> The best might be to find and advertise with use cases and examples >> from other languages. >> (as mentioned, I don't really know where to start looking, otherwise I >> would have already shared something) > > > Oh, this was always going to be a controversial RFC. :) Operator overload= ing is controversial in most languages, even the ones that have it and don'= t really have problems because of it. It's the kind of feature that doesn't= affect most people most of the time, but that all developers end up having= a strong opinion about one way or another. I talked about that a little bi= t in the internals podcast episode I did with Derick. > > NumPy is probably the absolute best example of this feature being used. N= umPy is an absolute killer feature of Python, and drives an enormous amount= of the development being done in the language. It could easily be pointed = out that NumPy is the equivalent of an extension however, being compiled do= wn and directly hooking into the Python language. NumPy is also not include= d in the core Python language, though operator overloading *is*, importantl= y. However, the toolchain for adding NumPy is much easier and consistent th= an the toolchain for PHP extensions in general, and NumPy didn't have to ad= d overloads themselves as part of the extension (or teach Python devs the r= ules around using them in general). > > So as another example, I'll pull up the math libraries in PHP. I maintain= a math library myself, but it isn't nearly as widely used as the works by = Mark Baker. The mathematical uses have been described here as "niche" and "= small". First let's see what Mark has to say about operator overloading (an= d this RFC specifically): > > > Likewise, I have libraries for Matrix and Complex Numbers, where this w= ould be an incredibly useful addition.... a similar RFC using magic was pro= posed 6 years ago, and sadly never made it :-( I hope this time it is accep= ted, especially as a new keyword feels better than magic > - Source: https://twitter.com/Mark_Baker/status/1477957056464359427 > > The libraries that Mark is referring to, markbaker/matrix and markbaker/c= omplex, have over 105 million installs combined on packagist. (Source: http= s://packagist.org/?query=3Dmarkbaker ) > > > And so would `$lineValue =3D $unitPrice * $quantity;` work fine, with l= ess words to read... and people who don't understand operator precedence wo= uld have problems with more complex mathematical formulae whether it was op= erator overloading or method name > - Source: https://twitter.com/Mark_Baker/status/1478137583989309440 > > > But why shouldn't it be `=3D=3D`... these are valid use cases for a com= parison; equally, vector additions ($vector1 + $vector2) are quite commonpl= ace in mathematics > - Source: https://twitter.com/Mark_Baker/status/1478131480383606787 > > Marco's response to the person who maintains the literal largest complex = mathematics library in the entire language was: > > > Yeah, so use matlab? > > This is what I'm struggling with. I am seeing a lot of things here that s= ound an awful lot like "that's not *my* use case, so no". That isn't how yo= u design the language. Nikita's objection to the syntax is much easier for = me to understand, because it is based on *language design*. > > Mathematics isn't something that is never used or never needed in PHP. Th= e idea that I need to justify this statement is somewhat alarming. I fully agree: Any language should aim at doing math well, natively. You should not have to want to go to another language for calculations. If this is the case, the language is incomplete. And I think modern PHP aims to be or become a "complete" language. If people currently don't use the language for math problems, this says more about the language than about the people. There is a potential here to enable new packages that solve new problems, that people would have done in another language in the past. > > I have provided not only a multitude of examples of use cases in the RFC,= but I have repeatedly done so on this list as well. I have provided exampl= es in mathematics and examples in other domains, such as with Collections, = with userland scalar objects. I've mentioned possible future scope to expan= d further into things like better support for query builders. I do not beli= eve the reason people vote no for this RFC is because they haven't been sho= wn any use cases. The use cases are self-apparent and have *also* been prov= ided, both within the current PHP ecosystem and outside of it. Both with ex= isting extensions and userland libraries. > > I sincerely hope that the reason someone votes no on this RFC isn't becau= se they think use cases don't exist or because the use cases are fringe. I = also hope that it's not because of "abuse", as this is a boogeyman that is = not supported by the ecosystems of nearly all languages with this feature. = The problem is that without those two objections, I'm left with few reasons= I could see to vote no, perhaps the most prominent being the one Nikita ra= ised with finding the syntax objectionable. > > The syntax offers a lot for future scope in my opinion, some of it not ev= en related to operator overloads. It provides us a better way forward for a= llowing objects to control casting, for instance. Many find the __toString(= ) implementation to be lacking. Controlled casting in C++ for example howev= er is accomplished with something like `operator (int): int`. Another sugge= stion that came through from the community after voting opened was to use s= omething like `symmetric operator` to show that an operator can be in eithe= r position. [..] That was me :) I suppose you are going to reply directly to that message. > [..] It also could provide us with some way forward on improving/deprecat= ing ArrayAccess. > > Burden on static analysis tools perhaps? But there are features that are = difficult on static analysis that have been accepted. (Enums comes to mind.= ) > > If anyone is voting no truly because they are concerned that there aren't= use cases to justify it, I'd like to hear that and what sort of examples t= hey are looking for, because I feel I have done this multiple times on this= list at this point. Tbh, I had to warm up to the idea myself. At first I only thought of all the potential problems that were already mentioned here. The main problem was I only thought of existing code, not of new code to solve new problems. -- Andreas > > Jordan