Women in Technology

Hear us Roar

  What I Hate About Your Programming Language
Subject:   Operator overloading in Java
Date:   2003-05-17 19:41:31
From:   anonymous2
Response to: Operator overloading in Java

> The philosophy behind that may be that
> overloading is not necessarily
> intrinsically "bad", but has the potential
> to generate unintuitive code.

On the other hand, if you've ever tried to make a nice matrix Class, you realize why operator overloading is so useful. Having the option available means you are able to apply a more natural coding style when it applies. Further, I have seen far too many unintuitive method and variable names to accept this argument.

> The one supported instance of String
> concatenation is a natural and intuitive
> use of overloading.

To continue my point, having to write something like

u = v1.add(v2);

to add two vectors (as used in Physics, i.e. magnitude and direction) is much more awkward than

u = v1 + v2;

in this context, since this style of infix mathematical notation is the most natural for the problem domain of Physics.

> Also, to eliminate it just in principle for
> consistency would deprive Java programmers of
> an extremely useful timesaver.

I agree that I wouldn't be as happy programming Java without the String concatenation operator. However, my argument for consistency would be in support of a general operator overloading mechanism rather than elimination of String concatenation.

-- Tahoma