Necessity of Operator Overload in Computer Languages
operator overload in python ruby perl
- python https://thepythonguru.com/python-operator-overloading/
- ruby http://nicholasjohnson.com/ruby/ruby-course/exercises/operator-overloading/
- perl https://perldoc.perl.org/5.8.8/overload.html
golang doesn't have operator overloading.
go frequently asked questions says:
Why does Go not support overloading of methods and operators?
Method dispatch is simplified if it doesn't need to do type matching as well. Experience with other languages told us that having a variety of methods with the same name but different signatures was occasionally useful but that it could also be confusing and fragile in practice. Matching only by name and requiring consistency in the types was a major simplifying decision in Go's type system.
Regarding operator overloading, it seems more a convenience than an absolute requirement. Again, things are simpler without it.
this is a problem.
actually, operator overloading may not be necessary, but defining new operator is extremely convenient when doing math.
for example, when you are doing linear algebra.
say, M and N are matrixes, v is a vector. you want to be able to write:
without definining operators, you have to write:
M △ N ▲ V
if we reduce the function name, it has the function form:
wouldn't that solve the problem? No, because, the question is really about, why is operator such as + - * / = needed in the first place? why can't they all be function form? The answer is, without operators, expressions becomes extremely cumbersome and unreadable.
things gets real complex when you have complex numbers in play.