1

I'm using the webgl framework three.js.

Most of the classes can be "cloned" via a .clone() method.

Wikipedia seems to be very strict when it defines "cloning".

In computer science, cloning refers to the making of an exact copy of an object...

However, i've encountered something like this:

const myClass = new Class()

myClass.foo = 'foo'

myClassClone = myClass.clone()

myClassClone.foo === myClass.foo //true

^ this is what i expect to see out of a "clone".

The documentation for the library does not seem to be consistent though:

https://threejs.org/docs/#api/core/Object3D.clone

Returns a clone of this object and optionally all descendants.

vs.

https://threejs.org/docs/#api/materials/Material.clone

Return a new material with the same parameters as this material.

I'm struggling with the second one because i've encountered something like this

myClass = new Class()
myClass.foo = 'foo'
myClass.bar = 'bar'

myClone = myClass.clone()
myClone.foo === myClass.foo //true
myClone.bar === myClass.bar //false

Depending on what foo and bar are, my clone may or may not behave like the original. It depends on what are considered as these "parameters" but it is still somewhat confusing.

What can i say about this situation.

  1. Can i use "(non)deterministic" to describe these .clone() methods? All of them, some of them?
  2. Are they appropriately named? These never return exact copies of objects since they have uuids, but one seems more "clone-like" than the other.
  3. what other rules and considerations could be made when cloning? Cloning attached event listeners and such may not be the best idea.
  • 2
    You're getting stuck on the word "clone." The supreme source of truth for how Clone methods behave is not Wikipedia; it is the associated technology's reference documentation. Whether the name is appropriate or not is irrelevant; that is the name the threejs folks chose to use. – Robert Harvey May 08 '18 at 21:42
  • Are there any best practices when choosing the terminology for an API? There has got to be some logic why this is called clone() and not hamburger(). Like copy comes in flavors deep and shallow, are there more such attributes that a clone could be described with? – Dusan Bosnjak 'pailhead' May 08 '18 at 21:46
  • 2
    All too often, a "best practice" is simply so because someone says it is. Five years later, we've all moved onto something else, and it become the new "best practice." Because of things like "software patterns," many software developers have come to believe that there must be some sort of gold standard for everything that happens in software development, when in fact that's not true at all. Software development is an exercise in tradeoffs; at the end of the day, the "best practice" is usually the one that most effectively meets your specific needs. – Robert Harvey May 08 '18 at 21:57
  • Ok, that sounds like something that can be taken at face value. Still, i'd like to know more terms to be able to describe a phenomenon. – Dusan Bosnjak 'pailhead' May 08 '18 at 22:57
  • There is also the matter of Deep VS Shallow cloning. Deep cloning kills re-usability of objects, but avoids surprises. – S.D. May 09 '18 at 09:00
  • It’s actually slightly more nuanced here. The library is following the holy word of the dom, where events are not copied. However the library has tight coupling with the render loop, so one can end up in a situation where the meaning of an object changes when doing a shallow copy, in that rendering context. – Dusan Bosnjak 'pailhead' May 09 '18 at 09:52
  • I think the analogy is I hear a duck quack, and i hunt it. I label it "duck" and leave it in a machine that the butcher society provided me to make a few clones of the duck. The machine can clone the duck but not my label. The procedure says that i am to deliver the clones to a butcher store. I leave them there, not seeing the butcher and leave. The butcher inspects the ducks, but unable to recognize the species tags them all as "birds". Probably a bad analogy lol. – Dusan Bosnjak 'pailhead' May 09 '18 at 18:44

0 Answers0