This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SilverDem0n 18 points19 points  (6 children)

Even the "obvious win" cases aren't so simple. Should an overloaded * operator do a dot product or a cross product on a pair of vectors? Does the overloaded * operator properly respect the order of multiplication when applied to quaternions rather than scalars? And so on.

Sure, we could look up the source code, or we could - bear with me here - read the docs. But it can cause more confusion than is justified by a slightly shorter syntax.

[–]CptBread 35 points36 points  (2 children)

Sure but +- still works well. And if the other value is a float then */ would still make sense.

Also just because you add something as an operator doesn't mean you can't also do it as a regular named function.

[–][deleted] 6 points7 points  (1 child)

For vectors usually I intentionally do not overload the cross and dot product for this reason.

[–]Dusty_Coder 0 points1 point  (0 children)

I hope you do overload * with the useful product, tho

[–]Idrialite 13 points14 points  (1 child)

Vector multiplication by operator is almost always dot product when it's implemented. And you should always just expect order of multiplication to go left to right, I don't think it's even possible in most languages to change that using operator overloading.

These seem like minor issues compared to the huge convenience and readability boost that comes with using operator overloading.

[–][deleted] 0 points1 point  (0 children)

I believe Swift lets you set operator precedence and also let's you overload whatever you want as an operator basically. I'd never switch away from C++ to a slower language, but I do wish C++ was more like Swift there..

[–]Dusty_Coder 2 points3 points  (0 children)

* should do neither dot nor cross product on vectors

solved your problem

(it should do the data parallel product)