News for hackers. Stuff that matters.
Re:Copying data is wasteful, mutating data is dangerous by alexhutcheson on Thursday January 09, 2020 @04:20PM (#22005908)
In other languages this is less of an issue, because function signatures can include information about whether the argument can be modified or not. For example, in C++:

    // 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.
Re:Copying data is wasteful, mutating data is dangerous by pansa on Friday January 10, 2020 @02:32AM (#22009083)
There is some convention in Python - for example `reverse` and `sort` are mutating, whereas `reversed` and `sorted` are not.

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.