Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116687 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 97833 invoked from network); 20 Dec 2021 21:59:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Dec 2021 21:59:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C24441804BA for ; Mon, 20 Dec 2021 15:03:10 -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-f172.google.com (mail-vk1-f172.google.com [209.85.221.172]) (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, 20 Dec 2021 15:03:10 -0800 (PST) Received: by mail-vk1-f172.google.com with SMTP id s1so7082054vks.9 for ; Mon, 20 Dec 2021 15:03:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZaVykWpISpJLY6Xf/2Z2ZjTW6dy4Ng62y3d5ntQiqk8=; b=fy5Er0XzyCCLhQq6Ej73owclG2lVs4y1MaQLkwxjvZV4YIuyjh9WwnjVWYoFn5VzRj 0vMyaTPo7TVwrOh5j0XwyKIXlUHuruOYsI36xeZz8cIwBaOv7b3C6TToLd7IZo9IjRkS qvuiwwE9L3qQoukvXT9Ngma/yEHLZVlwdiM8fvw4n1S29cPq+bWnO6Uc2jaa8A2+Kzgo qA8TA7XkmDqXKgO7wguAe7burxchrkiWUIXe2K4Xg1VQSfLCJxE6BwDPkKswScMt7lRZ vQmnaCv+0f1wZKnhzcrEdLgvbwTfYw9heeG48yAJJzet9dUaBYdJ+tRkPOvQ98oO6VaR roIA== 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=ZaVykWpISpJLY6Xf/2Z2ZjTW6dy4Ng62y3d5ntQiqk8=; b=dy+BJ2jc+EvmthFgRC16FXOldGV3F4Gyo1dPCdmMMKx+rRX4oOQOmLLRn/rpU46aWa DFem6Pe7iuPNpMUqvHCXjT6RiZJUYLn5GVf28akrS/QAdmyQKsTYxOeWJNYFSZXH+W0F BHiL6ST2bFtsDmLoE1nlx2hsvuqt4gth9QMpgj1mQqRwEKCGCqzmfQKmVDGhGksuG53t NhP8O1JXKFAJ4YTMrrsVlBT4wD7+WvYxp3gAakPIxhvD2dBtQZPKd3jFviQCg/7vBb3I UimI/NsTteDT1YnCqWtM4Seudn0ENTNHqAKYT9UMPRLWr6u0aWOyJRyHCauKobL7SEjy BBZA== X-Gm-Message-State: AOAM530LhrrAh/BN7R1VbOHlAKXMbHw7RQzfTkJsmGP3MyEgFnAJcI1Z F7C25kuYYR39NwmjKUygB2sMzqrMiLmQbjhj/3rFQ/q+plFSig== X-Google-Smtp-Source: ABdhPJxYP8WrbmUscFxgD51KcYiM1gl/AzgRuTYWGEqNwdRJbVejN9yDpc3/UMkhUvrIcbvKzwN8wIkQ1PH5Kq5EKN4= X-Received: by 2002:ac5:c2d2:: with SMTP id i18mr121716vkk.29.1640041388050; Mon, 20 Dec 2021 15:03:08 -0800 (PST) MIME-Version: 1.0 References: <44b3fb4b-4693-1639-c8c0-5e17296c196e@gmail.com> <4b58c011-ed87-ba87-201d-0cf8e4116c6f@processus.org> <67431363-cd1e-9575-7d51-0f4d265d05b9@gmail.com> In-Reply-To: <67431363-cd1e-9575-7d51-0f4d265d05b9@gmail.com> Date: Mon, 20 Dec 2021 23:02:56 +0000 Message-ID: To: Stanislav Malyshev Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] User Defined Operator Overloads (v0.6) From: Danack@basereality.com (Dan Ackroyd) On Fri, 17 Dec 2021 at 18:36, Stanislav Malyshev wrote: > > When reading > this code: $foo * $bar - how do I know which of the ways you took and > where should I look for the code that is responsible for it? When I see > $foo->times($bar) it's clear who's in charge and where I find the code. > Terse code is nice but not at the expense of making it write-only. Well, there's only two places to look with operator overloads, but yes you're right, using operator overloads for single operation is not a good example of how they make code easier to read. The more complicated example from the introduction to the RFC https://wiki.php.net/rfc/user_defined_operator_overloads#introduction shows how they make complex maths easier to read. The exact position of where that trade-off is 'worth it' is going to be different for different people. But one of the areas where PHP is 'losing ground' to Python is how Python is better at processing data with maths, and part of that is how even trivial things, such as complex numbers, are quite difficult to implement and/or use in userland PHP. Stanislav Malyshev wrote: > And again, what's the intuitive > difference between operators +=+@-+ and ++--=!* ? That's not part of the RFC. There's enough trade-offs to discuss already; people don't need to imagine more that aren't part of what is being proposed. > I have encountered > toolkits where the authors think it's cute to define "+" to mean > something that has nothing to do with mathematical addition Rather than leaving everyone to make the same mistakes again, this RFC might be improved by having a list of stuff that it really shouldn't be used for. At least then anyone who violates those guidelines does so at their own risk. Having guidelines would also help junior devs point out to more senior devs that "you're trying to be clever and the whole team is going to regret this". I started a 'Guidelines for operator overloads' here (https://github.com/Danack/GuidelinesForOperatorOverloads/blob/main/guidelines.md) - if anyone has horrorible examples they'd like to add, PR's are welcome. cheers Dan Ack