Re:Object Oriented Programming is Inherently Harmful
by Nursie on Sunday November 30, 2014 @01:53PM
(#8677646)
Many times though, the operator overloading is just a way to hide what's really going on, making it harder for the programmer to have a good grasp of either what the error conditions might be or why there's an expensive operation going on in a particular statement.
Re:Object Oriented Programming is Inherently Harmful
by SamReidHughes on Sunday November 30, 2014 @02:34PM
(#8677782)
Operator overloading is just a function call. Everything you say about overloading an operator could be said about the function call that would replace the overloaded operator. I've never had trouble recognizing that a use of an operator was being done with a non-primitive type, which is the only way the confusion you describe could possibly happen, and the problem you describe has never happened to me while working on C++ code. I don't know why you think it is even plausible.
Re:Object Oriented Programming is Inherently Harmful
by vardump on Sunday November 30, 2014 @03:36PM
(#8677990)
Operator overloading is a syntactic sugar trick that hides the real method call. Nothing more, nothing less.
It's useful in vector math, complex number math, matrix math.
Re:Object Oriented Programming is Inherently Harmful
by TheCoelacanth on Sunday November 30, 2014 @07:54PM
(#8678963)
Operator overloading is useful for a lot more than just math. Overloading * and -> is useful for pointer-like types. Overloading () is useful for function-like types. Overloading [] is useful for collections and overloading ++ and -- is useful for iterators.
Re:Object Oriented Programming is Inherently Harmful
by SamReidHughes on Sunday November 30, 2014 @08:48PM
(#8679101)
The overloading of (), [], and the like is used but it's not necessary. They could have been other named overloaded functions.
Re:Object Oriented Programming is Inherently Harmful
by Nursie on Sunday November 30, 2014 @02:41PM
(#8677807)
A function call is always a function call, an operator is not. It makes for more opaque code.
Re:Object Oriented Programming is Inherently Harmful
by SamReidHughes on Sunday November 30, 2014 @03:56PM
(#8678044)
Function calls aren't always function calls.
There is. For templates I'd think the role is obvious, for operator overloading, at least operator-> is indispensable.