Why Java Doesn't Need Operator Overloading (and Very Few Languages Do, Really)
Walter Bright
newshound1 at digitalmars.com
Wed Apr 15 18:02:27 PDT 2009
Don wrote:
> The number of operators that you can overload is very small and each of
> them is attached to very specific semantics that makes little sense
> outside the realm of scalars and of a few other specialized mathematical
> concepts (e.g. matrices).
Exactly right.
> Bingo! That's what operator overloading is for. **Don't overload
> arithmetic operators unless you are doing arithmetic.** I think the main
> problem with operator overloading in C++ is that that point wasn't
> explained well at all.
Even worse, by standardizing the << and >> for streams, C++ implicitly
endorsed non-arithmetic usages.
> The D spec could probably do a better job of it,
> but at least the ~ operator removes the temptation for people to use +
> to mean concatenation.
Yeah, does + mean vector addition or concatenation? There's no solution
to that problem if you don't have ~.
More information about the Digitalmars-d
mailing list