Le 22/03/2022 à 16:14, Sara Golemon a écrit :
On Tue, Mar 22, 2022 at 5:38 AM Robert Landers <landers.rob...@gmail.com>
wrote:
But why can't we have generic operator overloading in which case this could
be completely built by libraries in userland?
I mean... honestly, I feel like I come back around to this very quickly.
Generic overloading gives us much more at the end of the day and allows the
people using PHP day in and day out to make the actual decisions about what
any of these APIs should look like.
So while I said I wanted to avoid the firestorm suggesting userspace
overloading would bring, maybe that's the question to ask:
Who's just a hard-nope on userspace operator overloading? If your reasons
go beyond foot-gun (and that is a valid reason), could you share what those
reasons are?
-Sara
Hello,
I am a not so hard-nope against userland operator overloading because
it's magic. My day job is 20% writing code, 30% speaking with clients,
and 50% reading and using community code. Userland operators are not as
explicit as verbose method calls; and you can't ctrl-space an operator
in any existing IDE, it's not obvious at what they does when you read
code using them in most cases, and beyond that, in order to use them,
you have to read an external documentation. Not that I don't read
external documentation, but 80% of time, reading directly interfaces in
my IDE is enough to know what to do with an API. When an API uses
methods for doing stuff, code is auto-documented, when people start
overriding operator, not so much (at least not as easy to find and
understand at first sight) especially if the code is segregated behind
interfaces and those interfaces don't explicit the operators (At least I
hope that, if userland operators land, that interfaces will have a way
to explicit the override).
And in the end, operators are just sugar for method calls. I don't
dislike writing $c = $a->plus($b) instead of $c = $a + $b, I even found
that there's some kind of elegance behind writing stuff explicitly.
There's no feature in the world that would be blocked by the lack of
operator overloading.
Moreover, the << >> c++ style stream operators are no more than a way to
implement the string builder pattern, if I understand it well. Then why
can't simply we use a StringBuilder class and use methods such as
append(), prepend() and all ? It's much more explicit and much less
alien-like for most people.
Regards,
--
Pierre
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php