Constructors (starstruck noob from C++)

Steven Schveighoffer schveiguy at yahoo.com
Fri Jan 21 12:10:26 PST 2011


On Fri, 21 Jan 2011 14:54:53 -0500, spir <denis.spir at gmail.com> wrote:

> On 01/21/2011 05:27 PM, Robert Jacques wrote:
>> On Fri, 21 Jan 2011 08:16:24 -0500, spir <denis.spir at gmail.com> wrote:
>>
>>> On 01/21/2011 06:28 AM, Robert Jacques wrote:
>>>> void copyMembers(A)(A src, A tgt) if (is(A == class)) { tgt.tupleof =
>>>> src.tupleof; }
>>>
>>> What about this feature in Object under name "copy" or "dup"? Sure,
>>> it's not to be used evereday; but it's typcally the kind of routine
>>> that, when needed, we're very happy to find. And as shown by this
>>> thread the solution is clearly non-obvious (lol).
>>>
>>> By the way, why "dup" in D, instead of most common "copy" or "clone"?
>>> Is it also a legacy name? (Don't tell me we got this one from
>>> stack-based languages like Forth ;-) Anyway the semantics are totally
>>> different (*)).
>>>
>>> Denis
>>>
>>> (*) for very curious people: concatenative languages:
>>> http://concatenative.org/wiki/view/Concatenative%20language
>>> _________________
>>> vita es estrany
>>> spir.wikidot.com
>>>
>>
>> ".dup" comes from arrays, which already have a ".dup" property which
>> copies/clones them.
>
> Yes. I was in fact (unclearly) wondering where .dup for arrays comes  
> from. I mean, the obvious term --and short enough to not even look for  
> an abbreviation possibly making it obscure-- is "copy", isn't it? (*)

Not sure where it comes from, but dup also is a system call in Linux:

  dup, dup2, dup3 - duplicate a file descriptor

The terminology isn't really important as long as its relevant.  Perhaps  
dup was chosen to avoid confusion with STL's std::copy (which copies data  
into an already-allocated area)?  The difference is subtle.

In any case, dup is clearly here to stay as the way to copy arrays, I'd  
agree that it makes sense to re-use it as the way to duplicate objects as  
well.  I use it in dcollections.

> (*)
> Or do people really speak like:
> << Would you please make a duplicate of the guest list? >>
> in the US?

They might, it doesn't sound that odd to me, though copy sounds more  
common.

-Steve


More information about the Digitalmars-d mailing list