Add deepcopy operator := to avoid bugs

martin.demare
Tue, 02 Nov 2021 10:09:44 +0000
General Usage

When doing everyday data analysis, avoiding bugs is often more time saving than having great code performance. One of my reoccurring bugs is that I forget that z=x doesn’t create a copy of x if x is an array.

Therefore I suggest to add a new operator := which assigns by creating a deepcopy.

In the same spirit, a colon at the end of a function name could create deepcopies of the function arguments when passed to the function (such that in my_fun:(x) the input variable x can be manipulated without affecting the value outside the variable outside the function).

By using the above operator and function-syntax I agree to the resulting performance penalty. If the code needs to be optimised for speed at a later stage, it is not very hard to inspect the code, check that no variables are unintentionally changed, and remove the colon.

8 posts - 4 participants