News for hackers. Stuff that matters.
Re:Fix the unit test and open a giant hole everywhere by tylerhou on Saturday December 25, 2021 @05:27AM (#29682035)
I disagree that C++ makes expensive operations explicit; see the copy constructor and the copy assignment operators. C, maybe.
Re:Fix the unit test and open a giant hole everywhere by mgaunard on Saturday December 25, 2021 @06:09AM (#29682261)
A C++ developer would know what an assignment or copy entails and would spot them on sight.
Re:Fix the unit test and open a giant hole everywhere by tylerhou on Saturday December 25, 2021 @07:21AM (#29682698)
It's impossible to tell whether a specific line of code makes a copy without knowing the types of all values. i.e.

    std::vector<int> numbers = Func();
may or may not make a copy depending on the signature of Func. So it's not clear at the callsite how expensive that line of code is. This is unlike Go (which has this explicitly as philosophy) where you need to call a copy function/use append to make a copy of a slice.
Re:Fix the unit test and open a giant hole everywhere by mgaunard on Saturday December 25, 2021 @07:29AM (#29682745)
Knowing the declarations of the various names a piece of code uses is of course a requirement in order to understand what it does.

In that example, there would always be a move or copy there, though there are scenarios in which it might be elided.