Yes, there are many situations where operator overloading is essential to writing concise and readable code.
* Streams. >> and graphically represent what is going on, and allow the chaining together of multiple elements.
* Strings. + represents concatenation better than a "concatenate" method could. Even Java agrees.
* Iterators. hasNext and Next is overly verbose and unnecessarily complicated, compared to ++ and *.
* Containers. Subscripting (a[i]) is a very common operation and looks much clearer with nte subscripts than a "at" method.
* Function objects. Having objects which can be called just like functions, "object(argument)", is crucial to creating generic algorithms.
* Assignment and Equality. Assigning from one class to another using = is better than an "assign" method. Testing for equality with == and != is much clearer than an "equals" method.
Anyway the whole "designing a new programming language" argument is wrong, because an operator is simply a function with a symbol and precedence. That is all. If operator overloading is defining a new language, then so is writing new functions.
Obviously people can misuse and overuse operator overloading, but that is true of any language feature and should be expected. You can design the perfect language, but it will always be possible for bad programmers to make a mess with it.
Yes, there are many situations where operator overloading is essential to writing concise and readable code.
* Streams. >> and graphically represent what is going on, and allow the chaining together of multiple elements.
* Strings. + represents concatenation better than a "concatenate" method could. Even Java agrees.
* Iterators. hasNext and Next is overly verbose and unnecessarily complicated, compared to ++ and *.
* Containers. Subscripting (a[i]) is a very common operation and looks much clearer with nte subscripts than a "at" method.
* Function objects. Having objects which can be called just like functions, "object(argument)", is crucial to creating generic algorithms.
* Assignment and Equality. Assigning from one class to another using = is better than an "assign" method. Testing for equality with == and != is much clearer than an "equals" method.
Anyway the whole "designing a new programming language" argument is wrong, because an operator is simply a function with a symbol and precedence. That is all. If operator overloading is defining a new language, then so is writing new functions.
Obviously people can misuse and overuse operator overloading, but that is true of any language feature and should be expected. You can design the perfect language, but it will always be possible for bad programmers to make a mess with it.