Operator overloading increases consistency. Instead of having
int a = b + c;
CustomNumberType x = y.add(z);
you have int a = b + c;
CustomNumberType x = y + z;Operator overloading increases consistency. Instead of having
int a = b + c;
CustomNumberType x = y.add(z);
you have int a = b + c;
CustomNumberType x = y + z;But not having operator overloading when dealing with vectors is maddening.
Person x;
Job y;
CustomType z = x + y;
WTF is Z?Is the argument, anyway, I support operator overloading.
Hopefully a type error, because no sane programmer would implement addition like this. Obviously an insane programmer could, but that’s not the fault of operator overloading. The following code is exactly as confusing:
Person x;
Job y;
CustomType z = add(x, y);Take a person, add a job, you get an Employee or EmployedPerson. Person.add(job).
I agree overloading can create footguns, but domain concepts should make a lot of sense in context when basic arithmetic operations are performed on them. Party = Meeting + Booze.
Custom operators are a big assistance for DSLs, and overloading can also aide their creation and elegance. Part of the “awesome but don’t be a jerk about it” toolbox.