copy -> shallowcopy and deepcopy -> copy ?


#1

I recently ran into this bug as only made a shallow copy of an array of arrays. Consequently the reference array was mutated afterwards and it took me quite some time to realise that copy is a “shallow copy”. Wouldn’t it be much more intuitive if copy would do a deep copy and something like shallowcopy is used for shallow copies? I know now when to use deepcopy, but I think many other users will run into the same issue.


#2

Or perhaps keep deepcopy as it is, and rename copy to shallowcopy. This would resolve any ambiguity.


#3

I think copy -> shallowcopy and deepcopy -> copy is a good idea: the no-brainer is the current deepcopy, thus should be the first stop. Why not post it to https://github.com/JuliaLang/julia/issues/20402?


#4

Didn’t know about that thread, I’ll post it there, thanks!


#5

I believe copy (shallow) is was is needed most of the time, so I would prefer the status quo. It’s already documented to be shallow, though its docstring could be improved to have a reference to deepcopy.


#6

FWIW, copy and deepcopy are used by Python too. In Swift, copies are shallow by default.


#7

Yes, this is not exactly a novel nomenclature – these are very standard names with similar behavior across various programming languages.