Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116772 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 89561 invoked from network); 3 Jan 2022 13:33:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jan 2022 13:33:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ACCA61804A7 for ; Mon, 3 Jan 2022 06:40:30 -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-vk1-f176.google.com (mail-vk1-f176.google.com [209.85.221.176]) (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 06:40:30 -0800 (PST) Received: by mail-vk1-f176.google.com with SMTP id u1so18667693vkn.10 for ; Mon, 03 Jan 2022 06:40:30 -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; bh=Bl8enyKvhRdWU2edgzNxhoIzFPs0lFMIuV+X0RLINi8=; b=oE0QbrgF25rIVwuE6TKMppqoyuxtsq0uq+rFiUIj30U808/Jy/aasJ2pq2bKJgDDyE 1Tuy2XmKXOvjnAyIsF7SQmym5Szivxvnvlh78eZnLNapy38FZeAXH7b1c0Ss2MMNkBsK MSliH8DomtC4582ZILFQBiCtDn0QXjFTQQxbq3pQxevYsDQYtAZMvFbYyGdwiPuF2Duc nz74FOEl6R8Gcg+Xops1+4YCJ1vnoTJmvIA2xw3o/xmTeL7YZaNW9FKOTuXbMalURL6/ t2cH06+GS1LCaiZyT6rWPMrGYlIBAlpfvGivcnt/9/CO18UUMIaDEm0OKPYrREySfE/l 5WHA== 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; bh=Bl8enyKvhRdWU2edgzNxhoIzFPs0lFMIuV+X0RLINi8=; b=p0eSNJVh9mDlowfleIE1z1qwSRcXmlXwBlV91CFHzO2uyZt17OSmParLPV1TSBxMoD 0tWT2N1VmDxETRwGNRSH4GcYEE4nVo7XwhWA8xNVfoOvwFUUhyfErbHe128XknIrUdaj wBtKqQAxKT31g1SYokhp5X1Zsz88Etlpwoh62wWYkKxPmDJlbYh+uHiDIZ4Om1eK9o+u LpizAquLP8Im/ybpFpCerzhkEMQWRHpEKEFcVFJkpFlOa+bgjoqEmDhf64MnP2tc1LYL uvlL9udSf6uZcdvjEiAdZcsDyQ1F/WiX7/UVxWUy3eU/iM7D5r0DskcTBFzyQ3YpIQBF CfhQ== X-Gm-Message-State: AOAM531a0xgaE7iWDt5iWzfv11c17iRS6YY1vOO7itHcOVhpzefO9MpK pKP9fUZ8Vqds/7EKJIcxlzgtNjCf5vqapyp+WwgAqWM7kgAmYy3d X-Google-Smtp-Source: ABdhPJxrwq9Cc15iaGJoYDwhdFPAks3EVRl+OFyuGwm+OaN9aFc2lTRMt+7qTrSXHHMQItD/Z9CSR58dwxVUF4nYv9Y= X-Received: by 2002:a05:6122:ca1:: with SMTP id ba33mr14745164vkb.14.1641220829337; Mon, 03 Jan 2022 06:40:29 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 3 Jan 2022 15:40:18 +0100 Message-ID: To: Marco Pivetta Cc: Jordan LeDoux , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [VOTE] User Defined Operator Overloads From: andreas@dqxtech.net (Andreas Hennings) On Mon, 3 Jan 2022 at 02:07, Marco Pivetta wrote: > > Hey Jordan, > > I've voted "no" on this one: infix functions may have been interesting, but > adding a whole new type system around operators is really not worth it, > given: > > * Added AST nodes > * Added method definitions for niche use-cases > * Complexity in support for static analysis tools > > I personally don't see a reason to introduce all this for examples like the > one with GMP, which was more readable before adopting userland custom > operators. > > In addition to all that, we didn't even achieve custom operators anyway: > it's just the built-in ones (this is why I mentioned infix functions), and > the precedence, number and type of operands are fixed too (yes, it is a > sensible starting choice, but very little "custom" about it). > > Overall, your RFC is exactly what I would expect a custom operator RFC for > PHP to look like: I just don't think the feature is needed at all, as it > only makes the language much more complex, for rare cases that I hope I > will never ever have to debug in future. Perhaps we need more discussion about use cases to justify this RFC? I think the main use cases mentioned so far were for arithmetic operations between value objects that represent money, time, or other measurable values, or mathematical higher-order values (vectors etc). I imagine that operator overloads can improve DX for these use cases, but at a cost for the overall language. How would you (Marco) see the future of arithmetic libraries for time, money etc without overloaded operators? How would these calculations look like e.g. with infix functions? Do you think this can eliminate the desire for operator overloads? E.g. something like this? $ts0 = new Timestamp($seconds0); $ts1 = new Timestamp($seconds1); /** @var Duration $duration */ $duration = $ts1 - $ts0; // Operator overload notation. $duration = Duration::betweenTimestamps($ts0, $ts1); // Static method notation. $duration = $ts1->diff($ts0); // Object method notation. $duration = $ts0 $ts1 // Infix notation based on static method. $duration = $ts1 $ts0 // Infix notation based on object method. I generally like names I can click on, if they don't get too long.. I like if the choice of implementation is knowable by just looking at the code. (with a small range of runtime polymorphism) I like if some functionality is implemented outside of object methods, keeping interfaces and inheritance chains simple. But for code with lots of calculations, a simple "-" feels simpler and more explanatory than something like "diff" or "timediff", where I have to reference and remember a specific method/function name. -- Andreas > Greets, > > Marco