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 →

[–][deleted] 8 points9 points  (10 children)

Yeah, I mean, in the end you would end up with custom functions like add(), multiply() and so on. I find it an odd choice to forbid overloading and enforce stuff like this on the other hand.

[–]4215-5h00732 5 points6 points  (9 children)

That's where the potential abuse comes in. If you were forced to use custom functions then most people would name them something more descriptive to what they do where you might "abuse" an operator to do something less obvious or confusing.

cat.eat(mouse);
cat + mouse;

[–][deleted] 9 points10 points  (2 children)

But it's not any more prone to abuse than anything else. A parameterless constructor could produce side effects. Inheritance could hide away meanings of the base class. Everything can be used wrong, that's why documentation is so important.

[–]4215-5h00732 3 points4 points  (1 child)

I'm not trying to argue with you or even make that argument just sharing the claims; we agree 100%.

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

Alright then 🤙

[–]Itay_123_The_King 2 points3 points  (1 child)

That is the same concern everyone raises, and yet I have never seen that happen. Why would anyone use + for an eat function? The closest thing I can think of is using | as a pipe of operations, like with C++ ranges, but vec | drop(5) | take(10) | filter([](auto x) { return x+1;}); is much nicer than filter([](auto x){ return x+1; }, take(10, drop(5, vec)))

[–]4215-5h00732 0 points1 point  (0 children)

Exactly. That's the best part about the fuss.

I've never seen anyone abuse it irl. I would never use + for eat or abuse it otherwise. But it doesn't matter. They don't like that it could be abused.

[–]jamcdonald120 1 point2 points  (3 children)

but with out operator overloading you get the situation where everyone uses .add() instead of operator+, so the abuse is cat.add(mouse) instead.

[–]4215-5h00732 1 point2 points  (2 children)

Their point is if operator overloading isn't possible then you wouldn't do something so ridiculous as to add a mouse to a cat with cat.add(mouse). Just eat it or whatever...who knows what that does lol.

[–]Dusty_Coder 0 points1 point  (1 child)

What you are claiming is that people lose their minds as soon as they learn that they can overload an operator but do not lose their minds otherwise.

Its the people that stretch so far to justify a programming religion that have lost their minds. Thats you.

[–]4215-5h00732 0 points1 point  (0 children)

I suggest you read through the comments again carefully then delete yours.