Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109266 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11291 invoked from network); 24 Mar 2020 12:17:52 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Mar 2020 12:17:52 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 644E21804DD for ; Tue, 24 Mar 2020 03:42:15 -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,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-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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, 24 Mar 2020 03:42:14 -0700 (PDT) Received: by mail-lf1-f45.google.com with SMTP id j188so8906561lfj.11 for ; Tue, 24 Mar 2020 03:42:14 -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 :cc; bh=YFIyBA8vEkKAeL0Be+0Y7TmO7VOYjZpBZYHaGXNn9Ds=; b=VVS+XUnccJPXwmEvo5xXGu3gtBHxm0SI3JwZNmCbB/Fu7kuStdBCL1L19NYGksVp4P I8Iy8RJAy8n26aAezSmnMWxx0SEavaqus7dlTgBrx/SUASHp1PAUqJjWUsoNqnSRkGt5 qWhbJkfow5BMKU+ZYhwlFEFmZioiwyzF3u3P0t5kjmDAkEyzRsrWpCsyKKX+hKAUMxq+ rTv3kLQc7dPZgqDeOZytogBOnhNsZTznoNZg4Iosr335EvgB/1BSsKtjRbIFWnPH4HTr FdkxjvTWIHXdCyu+Bp0PRBrFZIQBbkGtZyGHSeiZRDlXlJWrUkU8z5AQHlEMU1I0Exn2 YxgQ== 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:cc; bh=YFIyBA8vEkKAeL0Be+0Y7TmO7VOYjZpBZYHaGXNn9Ds=; b=ffre9biGEXRenlqe81C0QLSUFM6YHP/ZWZcPUUB+yMVxht0GjWd4+/4tpMdSnt/Z+r 8cTixJggMGhfHQBKRme4EmHAgx5c4HhLfCdYDh68pKQ3ngGGjpI27ArSPJXdj+5OJVk+ WArPZ77KzCGb5BAFG8xaWRbm9yyhisUnNGki15Yj/zGRHjclUx10gmqPLj8NyrM11duX GzF1LUZpY1kUoDkE1AHax1EQTu33oBqVjZXajqGAGkNlmoHx/NQyGvyjKLihYCQgdNpA /gDNbUubBy8u4xef4VLqRSytvXMdyPN8WP5w6GA5lzt1EI3r+VqJBKhE1RUjTkID1i0S 1xKw== X-Gm-Message-State: ANhLgQ2DF85F8gxNay6Tt5d55xoPa2nYiDmavCnUd6TrNoZ14b8uyJxD 9mGmdImVZxmrUKA0fRp8o67ddfZNFXOWGr2pJXw= X-Google-Smtp-Source: ADFU+vvQemFsYlgW++KauRZJHCDw9U5gMunUC52y9RDKUjTDWcLPwzyuqfgzPDjI0aHwPcq9Qk9r/nN/DKj503J9uG4= X-Received: by 2002:a19:761a:: with SMTP id c26mr4442469lff.190.1585046533423; Tue, 24 Mar 2020 03:42:13 -0700 (PDT) MIME-Version: 1.0 References: <003701d6013c$9afe9750$d0fbc5f0$@gmx.de> In-Reply-To: <003701d6013c$9afe9750$d0fbc5f0$@gmx.de> Date: Tue, 24 Mar 2020 11:41:57 +0100 Message-ID: To: =?UTF-8?Q?Jan_B=C3=B6hmer?= Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000093c56005a197673c" Subject: Re: [PHP-DEV] [VOTE] Userspace operator overloading From: nikita.ppv@gmail.com (Nikita Popov) --00000000000093c56005a197673c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Mar 23, 2020 at 6:58 PM wrote: > Hi internals, > > I have opened voting on > https://wiki.php.net/rfc/userspace_operator_overloading, which allows > users > to overload operators in their own classes. > > Voting closes on 2020-04-06. > > Regards, > Jan B=C3=B6hmer > To offer a counter-point, I voted yes on this proposal. A couple of thoughts: 1. This is exposing functionality that already exists for internal classes to userland classes. As a general rule, I think we should always strive to have behavioral parity between internal and userland classes. 2. Because this just exposes existing functionality, the amount of technical complexity this introduces is very small, especially compared to the significance of what this enables. The implementation complexity of RFCs is increasingly becoming a problem, due to the complex way in which existing language features interact. This RFC does not fall into that category. 3. As mentioned, this functionality already exists internally and is used by GMP, where it works (imho) very well. Of course, this is also something of a poster-child use case for operator overloading, in that the object literally represents a number. But there are plenty other similar examples, some of them very relevant to PHP (money represention). I think there is a somewhat irrational fear that operator overloading is going to be misused... but having worked in quite a few languages that do support operator overloading, I think I've only encountered this in two instances: First, the infamous use of << and >> as stream operators in C++ (which is really horrible, and gives operator overloading a bad name everywhere). And second, the use of / as a path concatenation operator in some libraries. And I think that's it. All other uses I've worked with were things like arbitrary-precision integers, floats, decimals or rationals; complex numbers, vectors, matrixes or tensors; bit vectors, constant ranges, known bits representations. Operator overloading is not a feature that is commonly needed or should be used much, but it does tend to make code a *lot* more readable in the cases where it is useful. I think people might also find this blog post by Guido interesting: https://neopythonic.blogspot.com/2019/03/why-operators-are-useful.html Regards, Nikita --00000000000093c56005a197673c--