Operator Overloading RFC is in voting. What are your thoughts on this feature?
Personally I feel PHP needs this RFC.
It adds parity between the built-in features and userland features of the language, because we already have overloaded operations for some internal classes.
It also will surely make life easier for some math libraries, while other libraries that do not require this feature will not be affected at all.
Sure it might be misused just as any other feature of the language currently. Many modern programming languages have this feature and it turns out to be a very useful tool (Python, Rust, C#, C++ to name a few).
I also like the operator +() approach of this RFC instead of the magic method approach of the previous one.
The link to RFC (and the voting).
The link to the discussion mailing list thread.
The voting has just started and does not already look promising, but I wanted to know what the community thinks of it.
Posted Jan 3, 2022, 12:51 PM UTC
I voted yes, on here and on the RFC.
Mathematics is an area where the PHP ecosystem does not get much love compared to alternatives such as Python.
Mathematics / data modelling / ML are some of the fastest growing sectors in software development. They are also key entrypoints for people who are being introduced to software development and the larger programming language ecosystem for the first time.
This RFC provides tools to improve PHP's long-term appeal and competativeness in these fields.
That can only be a good thing.
While I agree with your perspective, is there something that leads you to believe PHP would be adopted for ML if the language had these additions?
All of the data scientists and data engineers I've worked with would refuse out of principle, and the less-technical ones (great at math, poor at coding) struggle to program in the tools they're already familiar with. All of the evidence I've encountered indicates that nothing short of a Thanos snap-like experience that vanishes Python and its related tooling from existence would lead to PHP being adopted in that space.
Let's also not forget about all of the Fortran-based underpinnings in the Python math libraries. Those would similarly need to be ported across for... many reasons.
While under very rare circumstances I would find operator overloading valuable, they're not what's holding back PHP from being adopted in the ML space.
RFC author here. I will be bringing many improvements to PHP in this space in general. PHP is better for this kind of application than Python as a language, it just doesn't have the language features to support it right now.
So I've made that my mission.
I won't debate you on how well or not PHP can serve this area of technology and computing (I think you're correct there, and in any case I'm biased in favor of PHP and strongly against Python).
But the "as a language" is doing a tremendous amount of work in that statement. There's no ML/DS ecosystem, no motivation to switch, and an army of relatively stubborn data scientists that will try to murder you if you want them to use anything other than Pandas. Code and language quality is very often not a concern for them. Being forced to add semicolons and write out
functioninstead ofdefand use$everywhere certainly won't sell them on anything, and the vastly better type system is an anti-feature for them if the code I've seen is anything to go by.Well, I don't want to sound like I'm dismissing those things as unimportant, but what I'm focused on is the idea that those problems can't be solved unless the language actually supports the domain first. I'm trying to focus on the features themselves before looking at how adoption could be driven.
I absolutely love this RFC, especially with operator instead of magic method (as before).
I hope it will pass and have a question: would this RFC, or one in future, allow implicit interface implementation like how Stringable and BackedEnum work?
Simplified example; if class has:
it would implicitly implement
Addable<Money, int>?I think PHP 8.1 and upwards in future has great potential, both in terms of speed and language features, for applications such as ML outside of web development, with a lower barrier of entry to get started in that field than almost any other language to boot.
I agree that convincing people outside the existing PHP ecosystem of this is in practice more difficult and operator overloading wouldn't help solve the problem.
But regardless, in a world where you do want to use PHP for this kind of problem solving, you don't need operator overloading to do it. Python does support overloading and I've seen plenty of ML-type libraries which don't make use of it. It's a feature which ultimately tends to lead to confusion and design mess, because operators suddenly have a multitude of different meanings which aren't transparent.
I'd much rather see PHP's type system further developed and the ability to overload function signatures. We can partially do that at the moment with spread or union types, but we can't neatly do:
function foo(int $x, A $y) { ... }
function foo(int $x, B $y) { ... }
which would be far more useful, imo.
And something to specify strict arrays like:
function foo(int $x, array[A|B] $y) { ... }
would be fine.
This is literally impossible and will never happen. It has been said countless times by core devs who know more about the engine. [1] And in particular Nikita.
So maybe it would be more useful, but this is an even harder barrier than generics.
What gives someone voting rights on RFCs, out of interest?
Usually contributions to php-src or the documentation.
What kind of contributions though? Loads of people have added something to php-src or the docs and AFAIK they don't all get to vote? Who decides?
Dedicated contributions