4 ms·
Isn't operator overloading something else than the ability to define custom operators?
by timjver 8y ago
Isn't operator overloading something else than the ability to define custom operators?
- btilly 8y agoWhat people do in practice with operator overloading is turn regular operators into custom operators that do something different. Your ability to customize behavior is not as extreme as being able to make any custom operators that you want. But the tradeoffs are definitely related.
- seanmcdirmid 8y agoC# supports operator overloading but not custom operators. That means vectors get to use the plus operator for addition, but no Scalaesque ~~/ operators. C# is not a language that is generally criticized for operator soup like the ones that support custom operators.
- ainar-g 8y agoCounter-examples: * C++ uses bitshift operators for IO. The (in?)famous std::cout << "hello world" << std::endl; Which is such an improvement over puts("hello world"); * Ruby on Rails components sometimes redefines `=` as a hash merge. E.g. this config.action_mailer.default_options = {from: 'no-reply@example.com'} actually adds `from` to the default options instead of overriding it completely.
- btilly 8y agoC# may not be generally criticized for that. But there are certainly C# code bases that do get so criticized.