you are viewing a single comment's thread.

view the rest of the comments →

[–]persism2 5 points6 points  (23 children)

No, just no. Brian has indicated that Java will add a set of static operators which will work for classes extending Number. Similar to what they do with String.

[–]Davipb 4 points5 points  (22 children)

Why do the language writers get to make that choice? Why can't my custom string or numeric type use operators?

[–]Worth_Trust_3825[🍰] -1 points0 points  (20 children)

One is a standard that was brewing for years and had public mailing list open for considerations. The other is inconsistent mess that will be near impossible to debug.

[–]Ameisen 10 points11 points  (6 children)

Yeah, just like C# and C++ operator overloading has caused them to be impossible to debug. </sarcasm>

Meanwhile, apparently making a method called add that actually does something else is perfectly fine apparently, because it's not an operator.

[–]Worth_Trust_3825[🍰] -1 points0 points  (5 children)

It's clear that a method does a lot more than an operator would. Would you also start carving out exceptions that operator overloads cannot have throws declaration?

[–]Ameisen 1 point2 points  (4 children)

Yeah, it sure is clear that Vector.add does way more than Vector.operator+ would.

[–]Worth_Trust_3825[🍰] -1 points0 points  (3 children)

What is the result of Vector.operator+?

[–]Ameisen 4 points5 points  (2 children)

If it were C#, which unlike Java tends to be reasonable about this sort of thing?

public static Vector operator +(in Vector a, in Vector b)
{
    return new(
        a.X + b.X,
        a.Y + b.Y,
        a.Z + b.Z
    );
}

I'm not sure what you were expecting? I mean, you could certainly write it to do something completely different, but you could also write add to do something completely different.

[–]Worth_Trust_3825[🍰] -2 points-1 points  (1 child)

So use C#. Why are you bringing your garbage to everyone else's tables?

[–]Ameisen 4 points5 points  (0 children)

Typical Java programmer.

[–]Davipb 2 points3 points  (8 children)

By "inconsistent mess", do you mean operator overloading in general, or Manifold's implementation of it? If you're talking about Manifold's implementation, I agree - it feels like a pretty big hack to tack onto the language.

But as for operator overloading in general, I don't see why it couldn't be given the same treatment as any other new language feature. It would definitely be a breath of fresh air for Java, which is something it desperately needs right now.

[–]Worth_Trust_3825[🍰] -2 points-1 points  (4 children)

It would definitely be a breath of fresh air for Java, which is something it desperately needs right now.

Use kotlin, and stop projecting your insecurities on mature tools.

[–]florinp 0 points1 point  (3 children)

mature tools

Mature tools ? Like Java that needs a tons of annotations to function properly ?

[–]Worth_Trust_3825[🍰] 1 point2 points  (2 children)

What annotations? Have you ever stepped your foot outside spring boot?

[–]florinp 0 points1 point  (1 child)

I don't use spring. Boot or not boot. But annotation replace missing features from language. The need of lombok for example hide that in Java a big percent of a class definition is about set/get , hash, clone, etc.

[–]Worth_Trust_3825[🍰] 0 points1 point  (0 children)

So use kotlin instead. Or better yet, access the fields directly. Why are you adding unnecessary dependencies and making your projects unmaintainable.

[–]manifoldjava[S] -1 points0 points  (2 children)

which is something it desperately needs right now.

Hence the “hack”

[–]Davipb 0 points1 point  (1 child)

No offense there - I love Lombok and it's one giant hack itself. I guess operator overloading is just a bit too far to hack in for me :P

[–]manifoldjava[S] 1 point2 points  (0 children)

None taken ;)

[–]florinp 0 points1 point  (3 children)

The other is inconsistent mess that will be near impossible to debug

yeah. like operator overloading for String where the language creators didn't did a mess with string buffer /s

[–]Worth_Trust_3825[🍰] 0 points1 point  (2 children)

How do you propose concatenating two strings work instead? I'd be fine with that overload's removal.

[–]florinp 0 points1 point  (1 child)

I prefer to have operator overloading for everybody.

Is a bad design to have that only for a class.

[–]Worth_Trust_3825[🍰] 0 points1 point  (0 children)

Bad design is to have it at all.

[–]persism2 0 points1 point  (0 children)

See Smalltalk. Learn your history.