|
|
|
|
|
by dgrunwald
1669 days ago
|
|
Operator overloading has been traditionally overused, especially in C++ (shift operators for iostreams, C++ iterators).
Java was the peak of the push-back against that. C# has operator overloading, but forbids many things that were possible in C++: * `operator=` and `operator ,`
* `operator new` and `operator delete`
* `operator +=` overloaded differently from `operator +`
* `operator &&` and `operator ||` overloading works differently in C#, so that it preserves the short-circuiting behavior
* `operator ++` only can be overloaded once in C#, with the compiler automatically handling the difference between pre- and post-increment
But more crucially, the C# standard library uses operator overloading only for types like `decimal` and `BigInteger`. C# programmers can go years without ever overloading an operator, while still profiting from it whenever they use `BigInteger`.
It's very different from the C++ culture where * everyone needs to learn about how to overload `operator=` (for memory management)
* the standard library encourage abuses of operator overloading such as shift operators for iostreams
It should be unsurprising novice programmers abuse operator overloading when the C++ language teaches them exactly that. |
|