▲ | moelf 4 days ago | ||||||||||||||||
> operator overloading, while it can make for cute-to-read code, isn't really a good idea for code readability and maintenance so should we write `add_int_int(1,1)` and `add_int_double(1, 1.0)` and `add_double_double(1.0, 1.0)`?... | |||||||||||||||||
▲ | HarHarVeryFunny 4 days ago | parent [-] | ||||||||||||||||
The expectation is that arithmetic operators are performing the corresponding arithmetic operations, so overloading for different arithmetic types (int, float, complex) doesn't produce any surprises or need to lookup operator definitions. Applying arithmetic operators to non-arithmetic types starts to become a problem, even if some cases (set union/difference, string catenation) are natural... The same goes for other operators... overloading '[]' indexing for maps as well as arrays seems natural, but would be highly confusing if you overloaded it for something unrelated to an index-like concept. | |||||||||||||||||
|