Arc Forumnew | comments | leaders | submitlogin
1 point by tokipin 6068 days ago | link | parent

> > It is true though that whenever you overload an operator you depend on the programmer understanding more about a single operation. Thus by definition overloading increases the complexity of a language.

that's if we're looking at it from the perspective of the operator. but if we look at it from the perspective of an expression, i think it is simpler. to illustrate: one of the nice examples on the front page of ruby-lang.org is the following (keeping their comments):

  # Ruby knows what you
  # mean, even if you
  # want to do math on
  # an entire Array
  cities  = %w[ London
                Oslo
                Paris
                Amsterdam
                Berlin ]
  visited = %w[Berlin Oslo]
 
  puts "I still need " +
       "to visit the " +
       "following cities:",
       cities - visited
if we look at it from the perspective of the operators, we see we've overloaded + and - for non-numeric types. however, if we look at it from the perspective of the programmer as they are writing those lines, we see that the programmer just wants to say "remove the cities i've visited from the cities i have to visit," and "cities - visited" is almost a direct translation of that. it makes sense. the fact that that operator happens to be overloaded from another domain is irrelevant. the context secures the role of the operator