operator overloading, when used judiciously, makes for code that is cleaner and easier to read
@jamey i'm talking specifically about things like overloading existing infix operators rather than inventing new ones
my personal thoughts are that it only really makes sense if it's intuitive what the operator means in context
the canonical example for me is overloading + on vectors (the mathematical sense) to implement vector addition, and maybe overloading * on vectors for scalar and possibly matrix multiplication. in those cases it's clear what a + b means, so the code is nicer to read
@jamey so if i want an affine transform aff(x) = Ax+b, i can just have the code say
A*x + b
instead of
A.mul(x).add(b)
or something more verbose and imo less clear
@typhlosion Yes, I strongly agree with you that mathematical uses of operator overloading are Good and Right and should be Encouraged. 😁
I think there are other uses of infix operators that are also good, but the lines are much more fuzzy to me.
And then there's C++ << and >> to read or print data on streams, which I think is Very Bad. 😅
@typhlosion Hmm! I think I agree, but that word "judiciously" is really important. I'd be interested to hear more detail on your thoughts about good and bad uses of operator overloading, and I think it makes a difference which language you're thinking about. e.g., since Haskell allows inventing any operator you want by stringing together arbitrary symbols, it feels quite different than the C++ habit of using every available operator just to make code more terse―but not always better!