Disclaimer
This post is about the correct usage of the terms "shallow-copy" and "deep-copy", specifically when talking about copying an object which does not contain any references. This question is not meant to be (and should not be) opinion-based, unless there truly is no consensus regarding this topic. I have tagged this question as C, but it might be language-agnostic, unless the meaning of those terms in that context is well-defined for specific languages but not for others.
Preface
The terms "shallow-copy" and "deep-copy" are commonly used when copying an object with references, in order to specify whether or not the copy is complete (independent of the original).
However, I have also seen this terminology used when copying an object without references, where both terms mean the exact same thing and there would be no need to differentiate. So far, I have not found a concise definition which would cover this particular use of those terms.
The definitions given on Stack Overflow (in the tags shallow-copy and deep-copy):
A shallow copy contains a link (address in memory) to the original variable. Changes on shallow copies are reflected on origin object.
A deep copy duplicates the object or variable being pointed to so that the destination (the object being assigned to) receives its own local copy.
Under these definitions, a copy of an object without references would be a deep-copy.
The definitions given on Wikipedia (in the article Object copying):
One method of copying an object is the shallow copy. In that case a new object B is created, and the fields values of A are copied over to B. This is also known as a field-by-field copy, field-for-field copy, or field copy. If the field value is a reference to an object (e.g., a memory address) it copies the reference, hence referring to the same object as A does, and if the field value is a primitive type it copies the value of the primitive type. In languages without primitive types (where everything is an object), all fields of the copy B are references to the same objects as the fields of original A. The referenced objects are thus shared, so if one of these objects is modified (from A or B), the change is visible in the other. Shallow copies are simple and typically cheap, as they can be usually implemented by simply copying the bits exactly.
An alternative is a deep copy, meaning that fields are dereferenced: rather than references to objects being copied, new copy objects are created for any referenced objects, and references to these placed in B. The result is different from the result a shallow copy gives in that the objects referenced by the copy B are distinct from those referenced by A, and independent. Deep copies are more expensive, due to needing to create additional objects, and can be substantially more complicated, due to references possibly forming a complicated graph.
Under these definitions, a copy of an object without references would be a shallow-copy.
I think both terms are inappropriate, because "shallow-copy" implies that the copy is incomplete, whereas "deep-copy" implies that some kind of special treatment (or high cost) is required for copying. Since copying an object without references is both complete and yet does not require any special treatment, I would argue that neither of those terms should be used. However, this post is not about what I think, but what is the current consensus (if any) in the programming community.
Questions
When I copy an object without references, would that be considered
- a shallow-copy (because no references are involved)?
- a deep-copy (because the target object is independent from the source object)?
- both?
- neither?
Is there a good term for a partial deep-copy, where some fields are shallow-copied and others deep-copied?