Argumnentation against external function operator overloading is unconvincing

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 25 08:25:38 PDT 2016


On Sunday, September 25, 2016 16:50:04 Andrei Alexandrescu via Digitalmars-d 
wrote:
> It seems you want to define ranges with similar syntax but subtle
> semantic differences, e.g. r.front and r[0] to mean different things.
> The entire Phobos is designed under the assumptions that ranges work a
> specific way, so in order to design a different mechanism you may want
> to use different syntactic interfaces.

The reality of the matter is that anyone who tries to define the range
primitives to work differently than how Phobos uses them (and druntime in
various places even if it's not in object.d yet) is going to be screwed as
soon as they interact with code written by anyone else. Anyone looking to
make r[0] do something different than give you r.front might as well just
redefine popFront to mean popBack and vice versa for all that it's going to
work with other people's code.

So, if they want their code to work with anyone else's code they pretty much
need to use their own set of range primitives that do not conflict with the
standard ones rather than trying to redefine the standard ones. And if they
don't care about interacting with anyone else's code, they can always just
fork druntime and Phobos to make them do whatever they want. But trying to
redefine some of the basic primitives that D's runtime and standard library
use while still trying to interact with anyone else's code is a recipe for
disaster.

- Jonathan M Davis



More information about the Digitalmars-d mailing list