Hi Rob,

> On Sep 10, 2024, at 4:31 AM, Rob Landers <rob@bottled.codes> wrote:
> This is very similar (behaviorally) to what I wanted to do with GMP. 
> Overloading GMP would have given you int-like powers in your type. The 
> biggest negative feedback I got was that people would abuse it still; so we 
> need some way to prevent abuse. If you read Jordon's operator overloads RFC, 
> and my GMP overloading RFC, you can see that users basically need a way to 
> define how to operate over even just an integer.
> 
> For example, Dollar(1) + Euro(3) is what? Or even Dollar(1) + 1? How does a 
> developer prevent someone from doing something nonsensical? The language 
> needs to enforce some rules and/or the developer needs to be able to define 
> them. These rules need to be intuitive and well reasoned, IMHO.

My arguments were that the use-cases where it is clear and objective what each 
operator would mean are few and far between[caveat, see below] and so rather 
than provide general operator overloading PHP should build those use-cases into 
a core extension. 

For example, to add Dollar + Euro, having a Money or Currency extension as part 
of PHP core would make huge sense to me, but not giving everyone the ability to 
overload operators for every type.

I did not follow the GMP discussions as I have never needed to use that 
extension in any of my own PHP development so I am not familiar with the 
arguments made and may be mischaracterizing your proposal; correct me if I do. 

BTW, where is your GMP RFC? I searched for it but could not find it.  Did you 
propose operator overloading for GMP in core, or in userland?

> For example, Dollar(1) + Euro(3) is what? Or even Dollar(1) + 1? How does a 
> developer prevent someone from doing something nonsensical? 

If the rules are built into core, then the compiler and/or runtime stops them 
from doing something nonsensical, right?

> The language needs to enforce some rules and/or the developer needs to be 
> able to define them. 

My argument is that the language should enforce those rules as allowing the 
userland developer to overload operators will result in every developer 
defining different rules for their own classes, leading to a tower of babble. 
And the chances that many developers will do things nonsensical with their 
operators approaches 100%. 

I do acknowledge not everyone agrees with me on this, and if so that is their 
right. If enough people disagree with me then PHP may eventually have general 
operator overloading. My hope is that there are not enough people who disagree.

> These rules need to be intuitive and well reasoned, IMHO."  


I hope anything that passes an RFC is intuitive and well reasoned because 
otherwise our governance model is flawed and maybe we need to address that 
first, if so?

-Mike

[caveat] — I am aware there are likely numerous use-cases in financial, 
scientific and/or related fields that could benefit from operator overloading 
but that would likely never be mainstream enough to make it into PHP core. For 
this I think making it easier to implement operator overloading in an extension 
would be a reasonable solution (if that is possible.) Yes, it would require 
people learn to develop extensions, but working groups for those use-cases 
could form, and if it could be done in a way that supports Zephir, then writing 
an extension should not be too hard. https://zephir-lang.com 
<https://zephir-lang.com/>

That, or come up with some way to limit operator overloading to only those 
things where overloads are objectively obvious, but I really have no idea what 
kind of limits could do that and I doubt it is even possible.

And if none of those things then those communities can get by with what they 
have always been able to do; use methods and parameters.  One thing is clear to 
me, PHP is never going to overtake Python (or Julia, et. al.) in those 
communities, so why appeal to a base that is not really interested except on 
the periphery? OTOH, Python is not likely to overtake PHP for general web 
development no matter how "popular" it becomes.

BTW, why has nobody ever mentioned Zephir on this list (that I am aware of?)

Reply via email to