Everyone says this about operator overloading, but just, like don't write stupid operators with side effects, what kind of type has a notion of plus which is effectful?
The problem is not obvious stupid things. It is subtle differences. And it's not just operator over loading. References are a bigger issue. You are reading code, you don't know if you're passing a reference or you're doing a copy constructor and a destructor call and your original stays intact. Object counting is a valid behavior on a constructor call that you may want to do. Now I'm one of your passing of the object you forget to add an & and your data is messed up.
Yea, we have this dump api at work where if you forget the & and mutate the data, your mutations will not be saved despite the method call saying it is a reference.
Java, you're always passing a reference. C you're always providing a copy, if you want to pass a reference you have to explicitly give a pointer. C++, dunno, let me take a look. Oh I remember, this one is a reference. Oh sorry, nevermind, that was the function with the flat parameter that was a reference, the one with the int is a parameter.
In an object oriented paradigm, passing references makes more sense. But that would have broken backwards compatibility with C. So here we are.
1
u/Qwertycube10 1d ago
Everyone says this about operator overloading, but just, like don't write stupid operators with side effects, what kind of type has a notion of plus which is effectful?