Re:C++23: The Next C++ Standard
by pjmlp on Tuesday July 11, 2023 @03:24PM
(#36686037)
How can you be sure that plus() and mul() actually do what they say?
[ Parent
| on HN ]
They're functions. Whatever they do, my code will go execute some code from whatever library implements them, which is what a function does. I just want to be able to rely on [] being an array subscript when I read some unfamiliar code. Is that too much to ask?
Just like the function that happens to be named [].
Re:C++23: The Next C++ Standard
by kristiandupont on Wednesday July 12, 2023 @01:14AM
(#36690686)
Can IDE's detect this and offer "go to implementation" on an overloaded operator these days? Because besides from the surprise-element in the fact that there even is code to debug hiding somewhere, not being able to quickly navigate to it is much worse in my opinion. And with infix operators where you can't even be sure which operand the implementation belongs to, figuring it out can be a bit of a detective task.
Visual Studio does show a popup, go to implementation, and if the implementation happens to be visible on the same screen, also highlights it.
If you’re using it right then [] is still an array subscript, just with a custom implementation for getting array elements
Re:C++23: The Next C++ Standard
by throwaway894345 on Tuesday July 11, 2023 @03:32PM
(#36686152)
You read the code. And unlike operator overloading, you know at a glance exactly which implementation to look at. There is no spooky action at a distance.
Re:C++23: The Next C++ Standard
by joshuamorton on Tuesday July 11, 2023 @04:05PM
(#36686539)
How, the functions might support dynamic dispatch or be overloaded based on types.
There's nothing that prevents me from implementing all of
plus(Int, Int)
plus(Int, Vec)
plus(Int, Mat)
plus(Vec, Vec)
plus(Vec, Mat)
plus(Mat, Mat)
and to know which `plus` is being dispatched, you need to know the types of both arguments, exactly the same as if `plus` is named `__add__` in python or `operator+` in C++.
Re:C++23: The Next C++ Standard
by throwaway894345 on Wednesday July 12, 2023 @08:09AM
(#36693362)
Yes, overloading is bad (operator overloading is a kind of overloading).
Re:C++23: The Next C++ Standard
by joshuamorton on Wednesday July 12, 2023 @04:44PM
(#36701398)
How do you do math without overloading? I have ints, floats, bignums, vectors, matrices, complex numbers, and potentially fractions.
You want every operation to have a distinctly named version for each other numeric type?
Maybe you can reduce some of those, but you can't really have interfaces without some overloading.
Exactly the same thing with functions that happen to use funny characters.
Re:C++23: The Next C++ Standard
by throwaway894345 on Wednesday July 12, 2023 @08:09AM
(#36693356)
Nah, there’s no spooky action at a distance when you don’t overload. You know concretely what code is running.
Have you ever heard of linkers?
Re:C++23: The Next C++ Standard
by throwaway894345 on Wednesday July 12, 2023 @01:30PM
(#36698320)
Have you ever heard of potatoes? Neither of them help you tell at a glance which code is being dispatched to.
Re:C++23: The Next C++ Standard
by Etherlord87 on Tuesday July 11, 2023 @03:51PM
(#36686400)
I think in this context what's important is if these functions are overloaded or not…
Which in any case also means the only way to be sure is to track down the implementation, the actual character set hardly makes a difference.
I agree. Function overloading is just as bad as operator overloading.