Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116776 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98692 invoked from network); 3 Jan 2022 14:45:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jan 2022 14:45:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 91B451804C4 for ; Mon, 3 Jan 2022 07:52:13 -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=0.0 required=5.0 tests=BAYES_00,BODY_8BITS, HTML_MESSAGE,KHOP_HELO_FCRDNS,SPF_HELO_NONE,SPF_NONE,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 ; Mon, 3 Jan 2022 07:52:12 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id AAC6851005CC for ; Mon, 3 Jan 2022 15:52:06 +0000 (UTC) Content-Type: multipart/alternative; boundary="------------MvAbjfjZ6OLnIPqtZvFJo7rK" Message-ID: <3225c921-9b26-d2e0-f76f-45fff6f5a12a@processus.org> Date: Mon, 3 Jan 2022 16:52:04 +0100 MIME-Version: 1.0 Content-Language: en-US To: internals@lists.php.net References: In-Reply-To: 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] [VOTE] User Defined Operator Overloads From: pierre-php@processus.org (Pierre) --------------MvAbjfjZ6OLnIPqtZvFJo7rK Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 03/01/2022 à 16:00, Marco Pivetta a écrit : > I'd probably use `$ts1->subtract($ts0)`, which doesn't seem to be that > unreadable, and there is no need to abbreviate it to "diff" either. > Whether it needs to be static methods or instance methods depends on > the wished API design. > > What this RFC aims at is a mathematical language, inside another > general purpose language: for complex expressions, I'd probably run it > in a subsystem dedicated to this instead. > > See for example: > >  * https://en.wikipedia.org/wiki/Expression_(mathematics) (I'm > literally just picking a complex example - don't even know how to read > that properly) >  * and its textual representation in > https://en.wikipedia.org/w/index.php?title=Expression_(mathematics)&action=edit§ion=1 > > > ```php > $expression = <<<'MATH' > f(a)+\sum_{k=1}^n\left.\frac{1}{k!}\frac{d^k}{dt^k}\right|_{t=0}f(u(t)) > + \int_0^1 \frac{(1-t)^n }{n!} \frac{d^{n+1}}{dt^{n+1}} f(u(t))\, dt. > MATH; > > $result = $userlandExpressionEngine->evaluate( >     $expression, >     [ >          // ... bind parameters here .... >     ] > ); > ``` > > Heck, I can probably ask the `$userlandExpressionEngine` to render > that monstrosity for me (see attachment). > > Note that we do this stuff constantly for SQL, yet we haven't designed > a system for embedding SQL into the language, and still, SQL is used > many magnitudes more than all what was discussed in this RFC. > > Yes, strings are problematic to some degree, but it's still better > than increasing language complexity for a very edge case. > > Alternatively, a better way to embed other languages can be used, > which would be much more useful for things like Twig, Blade, PHPTal, > SQL, etc: In haskell, this is done via Template Haskell, which many > like, and many loathe, but is still useful for type-safe operations > with a different language than the "main" one: > https://wiki.haskell.org/A_practical_Template_Haskell_Tutorial#Shakespearean_Templates > > In addition to all the above, I just noticed that the entire > reflection API in the RFC requires major BC breaks in the reflection > API... sigh. > > Marco Pivetta Hello, I personally tend to agree with everything that Marco said. Especially regarding the fact that it's adding huge complexity to the language itself for mostly edge cases. I'd argue there's many much more valuable features that could be added to PHP before operator overload, such as generics, rationalized collection API and scalar objects with methods for example (which all could be magnificent tools for improving the operator overload RFC). I'm not against explicit method call, it's both readable and navigable, whereas operator overload tend to magically hide what the code really does. Best regards, -- Pierre --------------MvAbjfjZ6OLnIPqtZvFJo7rK--