Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124034 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id E33761A009C for ; Sat, 29 Jun 2024 13:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719668151; bh=SWwkeO70rj1EaO50i4tLvjC+RluSOMJG97XLSVzcVVw=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=NGp69TQOcKstiygEfOKM/PKTh4nYgPIYIGLFnxGAAt5SWwx92CKBBEzBkrWT9g5Oc YMVA/abBDBY1LYfN2V8u8f+uP18ICh4fXRGsduCIYgQoAWbRz+ety+b5zUZN9122sY GjeXtnCWAq69u529X6mgo3puVLc9NqIJo2e4AQSMnybw5OoK4tyr4NejbPION2+63n vAL4bwUaP5zvB0A+ujw2LY/bAnX8StQDV1B1+TNt/IV5QQO30DRCqW/LsSPDB36XDM +BD7fcUt7TPYbRHqMtx+j8y3y1ncTZ3sHLR056rFxXGe6kZUshsadCDIWOknyil1J/ wdxiNUDVMkQ5w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 44FDD1805B8 for ; Sat, 29 Jun 2024 13:35:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 29 Jun 2024 13:35:49 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id EF1B41140078; Sat, 29 Jun 2024 09:34:29 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute1.internal (MEProxy); Sat, 29 Jun 2024 09:34:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1719668069; x= 1719754469; bh=SWwkeO70rj1EaO50i4tLvjC+RluSOMJG97XLSVzcVVw=; b=b 0//dJRI2xhjXxvK1unImh46WfaJ5Ep4/IxaholJQv0WV62fDQnI0EyEE2A+zUnKQ 1x4Au05a5Wpw+dAKQ94qnJm01Xthtzvp8bqvK9B6i+n/Nxo2+zWxOl2M0YVPqtsD +yklPE/s25LrDKFc4M8L03MepbdhugeyGtLgPycmdMIBVVIj6FwdqA6VYx77g3Y0 T1VVSWgi5zIMf/bs1OS91/3msTC+2gxS2jqoOjOteihoT7xvxHZvMWmTT17CzWY5 2gFozENTypiHHVBxVVXFH3xhoBv5E/XQYIxzwRn3/llokQ7YYFGJ10UOKrzrWQDg FUEtto+8O6UmUkXquw09Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1719668069; x=1719754469; bh=SWwkeO70rj1EaO50i4tLvjC+RluS OMJG97XLSVzcVVw=; b=J5fd3sjK6++zY1g+b8SCIB3quZUmQ0th0wyG1w7yGUqT ivqBYVi+9Tp/Hi2DHkaSV7JT/+LjitFjPEeSVtoj7fv7xPVHSnLT8+CSi/3yaHFb Lk4eaBKcsu18AnMRCwjk1bIOuvQLZNlqs2iko9bIZeURi8OXpWRd0FnoxQJ7Fo7+ 4klMu73s9nM2rkOR0wQ31G14YcKUNf3W9ZO/Z+4+MEYe0V3JbFoNfa9d/9d8+J3V FbK9yyO3uIz3IqEuIzut5gH1rV1SzEQ4uHGbrTC6xquqNhmy7W3ah9nbY1p3VDIP k+CPgnMLyuNTSqLaRzbnrKvvp8aa6sqUEm85xlqTxw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrtdelgdeijecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesrgdtreerreerjeenucfhrhhomhepfdftohgs ucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrg htthgvrhhnpedvheekteelveetfeevgeekgfffvdeuhfelveehvdetiefggedtfeejheet gffhueenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hrohgssegsohhtthhlvggurdgtohguvghs X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 4254F15A0092; Sat, 29 Jun 2024 09:34:29 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-538-g1508afaa2-fm-20240616.001-g1508afaa Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <90ab0ec1-33ad-4342-ad4b-6448ee89bfa7@app.fastmail.com> In-Reply-To: <89C9AC15-1456-46AE-9183-DFDA7D0D381D@sakiot.com> References: <90dd3eb6-c7be-4951-a6b6-fd3785ed92e5@app.fastmail.com> <89C9AC15-1456-46AE-9183-DFDA7D0D381D@sakiot.com> Date: Sat, 29 Jun 2024 15:34:08 +0200 To: "Saki Takamachi" Cc: "Jordan LeDoux" , internals@lists.php.net Subject: Re: [PHP-DEV] [RFC] Operator Overrides -- Lite Edition Content-Type: multipart/alternative; boundary=d00c28e55b25471480ca722c24b497ed From: rob@bottled.codes ("Rob Landers") --d00c28e55b25471480ca722c24b497ed Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, Jun 29, 2024, at 14:28, Saki Takamachi wrote: >=20 > Hi, >=20 >> On Sat, Jun 29, 2024, at 02:13, Jordan LeDoux wrote: >>>>> 4. The `static` distinction is also fairly meaningless, as in PHP = there is no situation possible where an operator overload can occur WITH= OUT it operating on objects themselves. >>>>=20 >>>> For this, that is the wrong approach. The actual behavior is on the= type, not the instance. The object instances may not even know their va= lue, they merely represent the value. >>>=20 >>> A GMP object instance that does not know its value? What are you eve= n talking about? Can you show me some code explaining what you mean? I h= ad literally months of this argument for the operator overloads RFC, and= studied the overload implementations in six other languages as part of = writing that RFC, I feel like I understand this topic fairly well. But I= do not understand what you are saying here. >>=20 >> A few minutes ago, I sent an email where I accidentally made the code= non-static, and I think I see the merit in what you are saying. It felt= so natural to use $this that I didn't even realize I was doing it wrong. >>=20 >> So, looking at your RFC and mine, I think this can be improved. >>=20 >> What would you suggest it look like and then we can work backwards fr= om there? >=20 > Here are my thoughts on your code. >=20 > In theory, inheriting from this "improved GMP class" would allow overl= oading of computational operators. >=20 > In effect, this acts like a "calcable interface", with the constructor= passing in meaningless values to the parent constructor and the add met= hod allowing the user to freely modify the return value. >=20 > This means that virtually any userland class can use the operator over= loading feature via a "hack". That is a very valid point, and I feel like it is something I definitely= would have thought about since I love abusing features to do things the= y shouldn't. My hope was that by removing the ability to directly compar= e, it would reduce the usefulness of "hacking it" into generic overloadi= ng since you have to return a GMP instance ... but then, I guess, that G= MP instance technically doesn't have to represent a number (though the r= est of the engine will very much treat it as a number). I will think on this some more... For example, while eating lunch, I was considering whether this even nee= ds to have anything to do with the GMP instance. I was only focusing on = the GMP class because right now, it is non-final. Then I started thinkin= g about Jordan's original proposal and how it could be simplified ... th= ere's certainly things to think about. > This approach is completely wrong.=20 Ouch, I would hope it would have something useful to it. :) >=20 > Rather than proposing this as is, it would be more constructive to pro= pose support for operator overloading. That's been tried before, and this was an attempt at the far other extre= me, "barely operator overloading". So, there is surely something in the = middle. Hopefully. =E2=80=94 Rob --d00c28e55b25471480ca722c24b497ed Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Sat, Jun 29,= 2024, at 14:28, Saki Takamachi wrote:

Hi,

On Sat= , Jun 29, 2024, at 02:13, Jordan LeDoux wrote:
<= div class=3D"qt-qt-msg3306475242208035808">
4. The= `static` distinction is also fairly meaningless, as in PHP there is no = situation possible where an operator overload can occur WITHOUT it opera= ting on objects themselves.

<= /div>
For this, that is the wrong approach. The actual behavior is o= n the type, not the instance. The object instances may not even know the= ir value, they merely represent the value.

A GMP object instance that does not know its va= lue? What are you even talking about? Can you show me some code explaini= ng what you mean? I had literally months of this argument for the operat= or overloads RFC, and studied the overload implementations in six other = languages as part of writing that RFC, I feel like I understand this top= ic fairly well. But I do not understand what you are saying here.

A few minutes ago, I sen= t an email where I accidentally made the code non-static, and I think I = see the merit in what you are saying. It felt so natural to use $this th= at I didn't even realize I was doing it wrong.

<= div>So, looking at your RFC and mine, I think this can be improved.
<= /div>

What would you suggest it look like and then we= can work backwards from there?

Here are my thoughts on your code.

= In theory, inheriting from this "improved GMP class" would allow overloa= ding of computational operators.

In effect,= this acts like a "calcable interface", with the constructor passing in = meaningless values to the parent constructor and the add method allowing= the user to freely modify the return value.

This means that virtually any userland class can use the operator over= loading feature via a "hack".

= That is a very valid point, and I feel like it is something I definitely= would have thought about since I love abusing features to do things the= y shouldn't. My hope was that by removing the ability to directly compar= e, it would reduce the usefulness of "hacking it" into generic overloadi= ng since you have to return a GMP instance ... but then, I guess, that G= MP instance technically doesn't have to represent a number (though the r= est of the engine will very much treat it as a number).
I will think on this some more...

<= div>For example, while eating lunch, I was considering whether this even= needs to have anything to do with the GMP instance. I was only focusing= on the GMP class because right now, it is non-final. Then I started thi= nking about Jordan's original proposal and how it could be simplified ..= . there's certainly things to think about.

This approach is completely w= rong.

Ouch, I would hope it w= ould have something useful to it. :)


Rather than proposin= g this as is, it would be more constructive to propose support for opera= tor overloading.

That's been t= ried before, and this was an attempt at the far other extreme, "barely o= perator overloading". So, there is surely something in the middle. Hopef= ully.

=E2=80=94 Rob
=
--d00c28e55b25471480ca722c24b497ed--