Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115772 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 62023 invoked from network); 23 Aug 2021 11:13:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Aug 2021 11:13:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4083C1804AD for ; Mon, 23 Aug 2021 04:47:02 -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.5 required=5.0 tests=BAYES_00,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, 23 Aug 2021 04:47:01 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id E445E5101324; Mon, 23 Aug 2021 11:46:54 +0000 (UTC) To: Jordan LeDoux , PHP internals References: Message-ID: <9aa7874a-a09b-4412-d98b-7c97b3d4439d@processus.org> Date: Mon, 23 Aug 2021 13:46:54 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------6A19689FE59595E4D95A25E5" Content-Language: en-US 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] Revisiting Userland Operator Overloads From: pierre-php@processus.org (Pierre) --------------6A19689FE59595E4D95A25E5 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Le 06/08/2021 à 18:34, Jordan LeDoux a écrit : > Hey all, > > ... > Hello, I'm sorry I couldn't answer the last few weeks I was on vacation. I just wanted to say, I'm opposed to user-land operator overloading for a few reasons: * it may produce shorter, simpler code, but it hides the real logic behind, * not all mathematical arithmetic operators have a semantic meaning for let's say, collections: it's not evident to me that "/" means partition (even thought the "+" for union is trivial), * they are hundreds different operations on collections which have a common taxonomy in many languages, there will never be enough operators for all, we will end up with Frankenstein API's where there will be operators for some operations, and methods for others, * methods in plain english (or whatever is your language) are always more readable in the end, * you can CTRL+click to navigate (in a decent IDE) on a method call, not on an operator, * step-debugging will be a bumpy ride, * some people will use them good, many will misuse them, some will do evil with those, * and hell, if "->" doesn't mean "access that object member" anymore, but "hey, the implementor could do anything at all instead", sky will fall upon us. I'm not sure the benefice-risk ratio is good enough. That said, in the other side, I'm +1 with equals(), compareTo() and those kind of magic methods for the "==" and comparison functions, this is something that PHP lacks, but I'm unsure this worth making all operators user-land overridable. I'm always favorable to something that makes the code being semantically and non-ambiguous to read, and in my opinion userland operators create more mess than they solve, they basically encourage people to make non-readable stupid shortcuts in their code. Best regards, Pierre --------------6A19689FE59595E4D95A25E5--