logoalt Hacker News

CuriouslyCyesterday at 4:06 PM1 replyview on HN

Honestly operator overloading is almost always a bad choice IMO. There are cases (e.g. matrix math) where it's the right choice because of semantic clarity, but the indirection it creates in exchange for readability is costly. It's always obvious when a function is being called, and how to navigate to the implementation, but the same is not true of overloaded operators.


Replies

AnimalMuppetyesterday at 4:14 PM

Well, it's like most tools. For this particular use, does it give more than it takes? If so, use it.

Matrix multiplication? Yeah, everybody knows there's a function being called. And, if it was implemented right, the users almost never have to look at the implementation.

Many other possible uses? Nope. Just nope. Not worth it.