Re: [RFC] Userspace operator overloading
| From: | Stanislav Malyshev | Date: | Sun, 16 Feb 2020 05:07:03 +0000 |
| Subject: | Re: [RFC] Userspace operator overloading | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108615@lists.php.net to get a copy of this message | ||
Hi!
> - The individual symbolic operators, with no intrinsic meaning - e.g.
> overloading . for concatenation on strings but dot-product for
> vectors; or a DSL overloading << and >> for "into" and "out
> of".
Please no. I know it looks fancy and some languages love it, but for a
person not in on the joke reading such code is a nightmare - it's
basically gibberish until you learn all the types and which meaning each
of the types assigns to operators. I mean, I could be maybe talked into
having users overload "+" to mean "add some kind of objects that are
like numbers but not actually integers" because my intuition still works
there even if I don't know the exact type. But if someone thinks it's
super-cool to override + to make it add element to the cache object -
please no. It's way worse than just using plain old ->addObject(). You
may save couple of keystrokes and make your code completely
incomprehensible for people who come after you.
I know DSLs have its niche but I seriously doubt average PHP user
implements a lot of DSLs that are required to work natively on PHP engine.
--
Stas Malyshev
smalyshev@gmail.com