Overloading relational operators separately; thoughts?
pineapple via Digitalmars-d
digitalmars-d at puremagic.com
Wed Sep 28 03:12:13 PDT 2016
I'd also like to point out a generally sound design principle:
Give the programmer as much power and flexibility as possible -
but don't forget to provide tools for simplifying common use
cases, and don't forget to define sensible defaults.
It makes a lot of sense that opCmp and opEquals exist, they fit
the by-far-most-common use case perfectly, but they aren't always
flexible enough for what the programmer wants to do. What if
comparison operators should return something other than booleans?
What if `!=` should be implemented differently from `==`? These
overrides great tools to have, but it would be better if they
weren't the only options we had.
Similarly, it makes a lot of sense that postfix operators are
rewritten in terms of prefix operators, but that's not always
flexible enough for what the programmer wants to do. It's a great
default to have, but it would be better if we also had the option
to define our own distinct behaviors for postfix operators.
More information about the Digitalmars-d
mailing list