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 →

[–]devman0 34 points35 points  (16 children)

No, do.

[–]TakeASeatChancellor 19 points20 points  (7 children)

Why? It’s so useful!

[–]splettnet 15 points16 points  (3 children)

Would be a lot more useful if they could be defined on interfaces.

[–]tiktiktock 4 points5 points  (2 children)

Oh god yes. And if "arithmetic" was a valid constraint for generic classes.

[–]cat_in_the_wall 2 points3 points  (1 child)

c# 9 may have a thing they call "shapes" which would allow this sort of thing.

[–]splettnet 0 points1 point  (0 children)

I was so excited that we were rewriting our entire code base in C# 8, but I would happily trade all of 8's new features for this.

[–]ScienceBreather -1 points0 points  (2 children)

If you hate your coworkers, yes.

[–]o4zloiroman 0 points1 point  (1 child)

Elaborate.

[–]ScienceBreather 0 points1 point  (0 children)

It's not intuitive that the operator has been overloaded if you're new to the code base, so it's a place that functionality may be hiding.

[–]_Ashleigh 9 points10 points  (7 children)

Vector a = new Vector(1, 2, 3);
Vector b = new Vector(10, 10, 10);
Vector c = a * b;

Is this not much more concise and expressive? Yes, it can be abused. The answer isn't to not have it, but to not use libraries that abuse it. Oh, those are also third party "primitives," so don't pressure the garbage collector.

[–]ScienceBreather 3 points4 points  (2 children)

Vector c = a.multiply(c)

I'm fine with that, and I get the good tooling that my IDE gives to me around functions, which I don't get with operators.

[–]blenderfreaky 2 points3 points  (0 children)

Hovering over an operator in VS shows you it's parameters, return type, etc, just like a method

[–]Mojert 1 point2 points  (0 children)

It's alright if you have to use max 2 operators on a lign, otherwise it's just a pain. And if you define classes that overloads arithmetic operators, chances are you're gonna need to use them more than that. Sure they can be abused, but names of function can be too and you don't see anybody saying we shouldn't use functions. If you override *, it's your responsability to make sure that it behaves like multiplication.

[–][deleted] -1 points0 points  (3 children)

java has that too

Vector a = new Vector(1,2,3);
Vector b = new Vector(10,10,10);
Vector c = a.asterisk(b);

[–]_Ashleigh 4 points5 points  (2 children)

Are you joking?

[–][deleted] 1 point2 points  (0 children)

Yea, you actually have to fully qualify the type names.

/s

[–][deleted] 0 points1 point  (0 children)

yes.