by alexhutcheson · 6y ago · 0 comments
// Definitely doesn't modify 'array', because 'array' is copied.
vector<int> Normalize(vector<int> array);
// Almost certainly doesn't modify 'array'.
vector<int> Normalize(const vector<int>& array);
// Probably *does* modify 'array' (otherwise author would have used
// const reference instead of pointer.)
void Normalize(vector<int>* array);
In Python every function uses the 3rd approach, so you have to signal to the user in some other way whether the argument will be modified or not. In Ruby and some other languages the convention is to append "!" to the function name, but in Python most people seem to just mention it in the docstring.However, I don’t know if there is a good reason why the mutating versions are methods and the non-mutating ones are standalone functions.