← Back to context

Comment by xigoi

4 hours ago

> I think operator overloading would be a very bad feature for an enterprise language like Java which needs to be consistent above all else.

Operator overloading increases consistency. Instead of having

  int a = b + c;
  CustomNumberType x = y.add(z);

you have

  int a = b + c;
  CustomNumberType x = y + z;

The problem with operator overloading is it makes things confusing when mixing types and let's programmers write confusing code.

    Person x;
    Job y;
    CustomType z = x + y;

WTF is Z?

Is the argument, anyway, I support operator overloading.

  • > WTF is Z?

    Hopefully a type error, because no sane programmer would implement addition like this. Obviously an insane programmer could, but that’s not the fault of operator overloading. The following code is exactly as confusing:

        Person x;
        Job y;
        CustomType z = add(x, y);

    • I don't know; you can bit shift an output stream by a string (or char array) in C++ (std::cout << "Hello, world!"). That seems pretty mad to me.

      1 reply →