Hacker News new | ask | show | jobs
by tylerhou 1636 days ago
I disagree that C++ makes expensive operations explicit; see the copy constructor and the copy assignment operators. C, maybe.
1 comments

A C++ developer would know what an assignment or copy entails and would spot them on sight.
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.
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.