<div dir="auto">My first impression also was that dependents should not observe the new object, be it a Model or anything else.<div dir="auto"><br></div><div dir="auto">Also Object has some template methods that in the base class do nothing. Since as Object has no state, it makes sense to me that its postCopy method should do nothing.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>> schrieb am Fr., 21. Aug. 2020, 21:26:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Christoph,</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Aug 21, 2020 at 10:55 AM Thiede, Christoph <<a href="mailto:Christoph.Thiede@student.hpi.uni-potsdam.de" target="_blank" rel="noreferrer">Christoph.Thiede@student.hpi.uni-potsdam.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">




<div dir="ltr">
<div id="m_-7427042413500455263gmail-m_-119406905160451368divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p>Hi all,</p>
<p><br>
</p>
<p>please consider the following snippet and its output:</p>
<p><br>
</p>
<p></p>
<pre style="box-sizing:inherit;margin-top:4px;margin-bottom:4px;padding:8px;font-size:12px;line-height:1.50001;font-variant-ligatures:none;white-space:pre-wrap;word-break:normal;border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-right-radius:4px;border-bottom-left-radius:4px;color:rgb(29,28,29);font-family:Monaco,Menlo,Consolas,"Courier New",monospace">o := Object new.<br style="box-sizing:inherit">o addDependent: 42.<br style="box-sizing:inherit">o copy dependents. "#()"</pre>
<br>
<p></p>
<p>In my opinion, this behavior is misleading for two reasons:</p>
<p><span style="font-size:12pt">1.</span><span style="font-size:12pt"> #copy is documented as to "<span>answer another instance just like the receiver." From an abstract view of the object, this should include the object's dependents, too. Afaik, DependentsFields
 is only an implementation detail, but in common sense, the dependents are just another part of the object.</span></span></p></div></div></blockquote><div><br></div><div>I disagree.  Dependents are a mechanism for observing an object. They allow external objects to register interest in a particular instance.  Those observers are not interested in observing the state of arbitrary copies, but of particular objects being observed.  In the history of Smalltalk-80 that I'm aware of from Smalltalk-80 v2 through to VisualWorks 7.x, copying did *not* copy dependents.  In fact, in Model, where for efficiency, Model>>postCopy did self breakDependents.</div><div><br></div><div>Before we go further, imagine inspecting some object.  An inspector updates its view of the object being inspected whenever that object issues a changed method.  Now let's inspect a copy of that object.  Wth your implementation both inspectors update whenever either object changes state.  This isn't at all what we want.</div><div><br></div><div>  Now for the actual bug.  If you look at copy for Model in Squeak, copy does *not* break dependents, and hence we get the behaviour you (think you) want:</div><div><br></div><div><div><br></div><div>(Model new addDependent: Object new; copy) dependents    =>   a DependentsArray(an Object)</div></div><div><br></div><div>This is a bad bug, and I only discovered it when I looked for a counter-example to your suggestion andfound that Model did (IMO) the *wrong* thing.  So if there is a bug, and I think there is, the fix is:</div><div><br></div><div>Model>>postCopy</div><div><span style="white-space:pre-wrap"> </span>self breakDependents</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div id="m_-7427042413500455263gmail-m_-119406905160451368divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p><span style="font-size:12pt"><span>2. If you run exactly the same snippet with a Model instead of an Object (which implements dependencies in a different way under the hood), the copied object will contain the original dependencies, still. I think we should
 unify this undocumented and unintuitive discrepancy. The Model documentation states it features "<span>fast dependents maintenance" so the behavior should be kept, just optimized.</span></span></span></p>
<p><span style="font-size:12pt"><span><br>
</span></span></p>
<p><span style="font-size:12pt"><span>How do you think about this?</span></span></p>
<p><span style="font-size:12pt"><span>Can we change the Object behavior or could this introduce any unpredictable consequences?</span></span></p>
<p><span style="font-size:12pt">And how could we fix it?</span><br>
</p>
<p><span style="font-size:12pt"><br>
</span></p>
<p><span style="font-size:12pt">And what about #shallowCopy? Unfortunately, it is called directly by more than a hundred senders in the Trunk image. Because DependentsFields is an implementation detail, </span><span style="font-size:12pt">I wonder whether #shallowCopy
 should copy the dependents as well. Should we move the actual primitive </span><span style="font-size:12pt">method</span><span style="font-size:12pt"> to something like #primShallowCopy and in #shallowCopy, </span><span style="font-size:12pt">update
</span><span style="font-size:12pt">DependentsFields after calling the primitive? Or do we rather consider #shallowCopy as a low-level method (similar to #veryDeepCopyWith: as apposed to #veryDeepCopy) and call it a code smell to call #shallowCopy from a
 far-away place?</span></p>
<p><span style="font-size:12pt"><br>
</span></p>
<p><span style="font-size:12pt">And LBNL: What should the following snippet output in your opinion?</span></p>
<p><span style="font-size:12pt"><br>
</span></p>
<p><span style="font-size:12pt"></span></p>
<pre style="box-sizing:inherit;margin-top:4px;margin-bottom:4px;padding:8px;font-size:12px;line-height:1.50001;font-variant-ligatures:none;white-space:pre-wrap;word-break:normal;border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-right-radius:4px;border-bottom-left-radius:4px;color:rgb(29,28,29);font-family:Monaco,Menlo,Consolas,"Courier New",monospace">o1 := Object new.<br style="box-sizing:inherit">o1 addDependent: 42.<br style="box-sizing:inherit">o2 := o1 shallowCopy.
o1 addDependent: 43.
o2 dependents asArray.</pre>
<p></p>
<p><span style="font-size:12pt"><br>
</span></p>
<p><span style="font-size:12pt">Should it answer: a) #(), b) #(42), or c) #(42 43)? :D</span></p>
<p><span style="font-size:12pt"><br>
</span></p>
<p><span style="font-size:12pt">I am looking forward to your opinions! :-)</span></p>
<p><span style="font-size:12pt"><br>
</span></p>
<p><span style="font-size:12pt">Best,</span></p>
<p><span style="font-size:12pt">Christoph</span></p>
<div id="m_-7427042413500455263gmail-m_-119406905160451368Signature">
<div id="m_-7427042413500455263gmail-m_-119406905160451368divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<div name="divtagdefaultwrapper">
<div><font size="2" color="#808080"></font></div>
</div>
</div>
</div>
</div>
</div>

<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div></div></div></div>
<br>
</blockquote></div>