Operator Overload

The last week I’ve been using Scala to work on a pet project of mine. It’s a relatively nice language, but one quirk (which I’ve also noticed in Haskell) is the extensive use of operator overloading.

For example, here’s a code completion pop-up:

I want to share a rule of thumb that’s useful for these situations:

  • Operators are functions
  • Functions should have useful names

If I’m operating on 2 integers, then +, *, /, etc. all have perfectly obvious interpretations. If I’m operating on a XML node then what do things like “/:\“, “\\“, and “\mean? And more importantly, is that meaning conveyed better then using an alternative such as ‘findAll’?

I hate to be curmudgeony, but there’s a point where I’d rather type ‘append’, then ‘+:=’.

Operator Overload