# copy -\> shallowcopy and deepcopy -\> copy ?

**URL:** <https://discourse.julialang.org/t/copy-shallowcopy-and-deepcopy-copy/7371>\
**Category:** Internals & Design\
**Created:** [November 28, 2017, 8:48pm UTC](https://discourse.julialang.org/t/copy-shallowcopy-and-deepcopy-copy/7371 "2017-11-28T20:48:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fgerick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fgerick/32/13228_2.png) [@fgerick](https://discourse.julialang.org/u/fgerick)\
**Post date:** [November 28, 2017, 8:48pm UTC](https://discourse.julialang.org/t/copy-shallowcopy-and-deepcopy-copy/7371/1 "2017-11-28T20:48:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 29, 2017, 7:10am UTC](https://discourse.julialang.org/t/copy-shallowcopy-and-deepcopy-copy/7371/2 "2017-11-29T07:10:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [November 29, 2017, 7:32am UTC](https://discourse.julialang.org/t/copy-shallowcopy-and-deepcopy-copy/7371/3 "2017-11-29T07:32:52Z")

</div>

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](https://github.com/JuliaLang/julia/issues/20402)?

---

<div class="post-metadata">

**Author:** ![fgerick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fgerick/32/13228_2.png) [@fgerick](https://discourse.julialang.org/u/fgerick)\
**Post date:** [November 29, 2017, 8:08am UTC](https://discourse.julialang.org/t/copy-shallowcopy-and-deepcopy-copy/7371/4 "2017-11-29T08:08:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [November 29, 2017, 10:09am UTC](https://discourse.julialang.org/t/copy-shallowcopy-and-deepcopy-copy/7371/5 "2017-11-29T10:09:25Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [November 29, 2017, 10:26am UTC](https://discourse.julialang.org/t/copy-shallowcopy-and-deepcopy-copy/7371/6 "2017-11-29T10:26:49Z")

</div>

FWIW, `copy` and `deepcopy` are used by [Python](https://docs.python.org/3/library/copy.html) too. In Swift, copies are shallow by default.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 29, 2017, 4:55pm UTC](https://discourse.julialang.org/t/copy-shallowcopy-and-deepcopy-copy/7371/7 "2017-11-29T16:55:52Z")

</div>

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