Hacker News new | ask | show | jobs
by timjver 2914 days ago
Isn't operator overloading something else than the ability to define custom operators?
1 comments

What 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.
C# 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.

Counter-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.
C# may not be generally criticized for that. But there are certainly C# code bases that do get so criticized.