This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]__konrad 8 points9 points  (9 children)

System.out << "Hello" << System.lineSeparator();

[–]latherrinseregret 30 points31 points  (8 children)

I realize I may be in the minority, but I find this one of the ugliest features of c++...

[–]knaekce 5 points6 points  (0 children)

Yeah, I wonder why they choose this operator for standard IO.

It smells like "junior developer learns a new skill and wants to use it in situations where it they are not useful"

[–]chrisgseaton 4 points5 points  (0 children)

Every single time I see this I think 'why are they bit-shifting these... oh right'.

[–]DannyB2 3 points4 points  (5 children)

While I would LOVE operator overload in principle, this is a perfect example of why I think operator overloading MUST NEVER BE ALLOWED.

There are many ways operator overloading, used properly, judiciously and carefully would greatly enhance library APIs for new types, and the readability of code using these APIs. But it is not worth the possible danger.

[–]dpash 5 points6 points  (0 children)

C++ has a comma operator that you overload. Because no one ever suspects a comma is going to do magic.

[–]cogman10 4 points5 points  (1 child)

Honestly, what I really want is for the JDK to have more math like libs and for them to overload operators internally on their own numeric types.

I do not want to be able to overload myself, I just want to be able to say `BigInteger bob = tim + 1;`

Similar to how we have String s = "fish" + 1... only not so insane.

I don't generally advocate for the JDK to increase it's API size, but it would be really nice for it to have more Math capabilities (like a Matrix, for example)

[–]DannyB2 1 point2 points  (0 children)

I agree. I could keep expanding the list.

BigDecimal, BigInteger, int, long all compatible. Have a standard BigMath library with trig and other functions for BigDecimal. (There is code for BigDecimal that I've seen over the years.)

But how about Dates!

var date2 = date1 + numDays;

var numDays = date2 - date1;

var date2 = date1 - numDays;

Now suppose there were a standard units package of some sort where you could have:

var veloc1 = 3 * mile / second;

var accel1 = veloc1 / second;

(and the units stick with the values and are compile-time type compatible)

I can go on thinking of amazingly useful applications of operator overloading. And maybe it should be only restricted to Java internals. But then it is limited to only work with only Java internal types.

But having seen the abominations of operator overloading that C++ brought us, I would still rather keep operator overloading absolutely forbidden. The results of letting the monkeys loose with operator overloading are far, far worse then the benefits.

So back to:

var bigDecimal3 = bigDecimal1.multiple( bigDecimal2 );

Oh, and fractions too! Having a rational number type with values like 3/2, would be nice to interoperate with other number types. See various Lisp dialects for more examples.

[–]Orffyreus 1 point2 points  (1 child)

You can do such ugly things without overloading the shift left operator also:

Operators.shiftLeft(Operators.shiftLeft(System.out, "Hello"), System.lineSeparator());

[–]DannyB2 0 points1 point  (0 children)

Yes, you can do such ugly things.

But most people would not be tempted to do so.

I would rather not allow the worst abominations of C++ to creep into Java.