-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tutorial intro talks of "shallow copy" concept without explanation #58320
Comments
Relevant line: http://hg.python.org/cpython/file/e2eccc906354/Doc/tutorial/introduction.rst#l487 When the concept is introduced, it appears like there's an assumption that the reader would know what it means. I'm curious if it's that common a term that it should be taken for granted, or if it deserves a definition. |
I think it’s a common English term (i.e. “shallow water” to describe a small lake-like thing where you can go without swimming), but non-native speakers may not know it (I don’t remember if I knew it before learning Python, for example). What about this: All slice operations return a new list containing the requested elements. This
-means that the following slice returns a shallow copy of the list *a*::
+means that the following slice returns a shallow copy (see the documentation of
+the :mod:`copy` module for a definition) of the list *a*:: (BTW, you can use syntax like Doc/tutorial/introduction.rst:487 to have links generated; see http://docs.python.org/devguide/triaging#generating-special-links-in-a-comment —also linked from the “Comment” label in the form, but it isn’t obvious that it’s a link). |
Even if they know the meaning of "shallow" (which is not a really common word AFAICT), they might not know what it means in this context. Adding an entry to glossary might be a better solution. In this context I think the best solution would be to actually show the implication of having a shallow copy with another short example (hijacking the reader to some other page where they can find some in-depth description of what "shallow" might do more harm than good). |
On 25/02/2012 08:09, Ezio Melotti wrote:
FWIW it's pretty much the only way of saying what it means. |
+1 for Éric Araujo's idea. |
On Sat, Feb 25, 2012 at 09:35, Éric Araujo <report@bugs.python.org> wrote:
That's kool, though I like Ezio's idea of putting it on a glossary
Thanks for the pointer. Note however that I chose my approach because |
However, even using "not deep" here would still be ambiguous. What's a deep copy? What's a non-deep copy? |
A link to a glossary may be better than a link to the top of the copy module. I wonder if we could use glossary markup in the copy module docs instead of adding terms to the global glossary. Tim: I like “undeep”, it’s used to describe a geographical feature of a river in The Lord of the Rings. |
"shallow copy" and "deep copy" are both standard computer science terms by no means unique to or invented by Python. We should be cautious about documentation bloat and trying to redefine standard terms. |
On Sun, Feb 26, 2012 at 00:11, Ned Deily <report@bugs.python.org> wrote:
Do they mean exactly the same thing in Python as what Wikipedia says? Anyways, some explanation (or link) would be needed since many people |
'Shallow' is a common English word: "Stay in shallow water until you learn to swim!" But that is not the issue here. I think the underlying issue is that the first sentence "All slice operations return a new list containing the requested elements." is wrong. Python lists, like shopping lists, do not 'contain' objects. Both contain references to objects (copies of their identifieres) and thereby define an abstract collection. A shallow copy of a collection object copies references (ids). A deep copy also copies objects themselves. (The Wikipedia article says much the same, but to me much less clearly.) If we start with a true sentence "Slice operations return a new list containing references to a subsequence of the original elements." or "Slice operations return a new list that defines a subsequence of the original sequence of objects", then I do not think more *needs* to be said. We could optionally add "Since no objects are copied, slices are shallow copies." both to emphasize that no objects are copied and to introduced the notion of shallow copy. |
FWIW, the shallow/deep terminology is not unique to Python and is commonly used in computer science. In my experience teaching Python, the terms are somewhat self-descriptive and only become perplexing when someone over-explains them. That said, a glossary entry is appropriate. |
Here is a patch that adds glossary entries for deep and shallow copy. I tried to keep them simple and clear enough. FWIW http://docs.python.org/3.4/library/copy.html also has a definition of the terms. If my definitions are OK I will add links to the terms were appropriate. |
The text talks about containers which, although often the case, is not general enough; copy() and deepcopy() can work with any object. |
How about we just like "shallow copy" to the copy module docs. That way, a person can follow-up with more detail if they're interested, yet still can read-on without interruption if they choose (this entry occurs *very* early in the tutorial). |
With /like/link/ I agree. |
Thanks Terry. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: