<body><div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000;text-align: left" dir="ltr">
                                        Hi Christoph --<div><br></div><div>> <span style="font-family: Calibri, Helvetica, sans-serif;font-size: 16px">Chris, you could override #inspectorClass on your MagmaCollection</span></div><div><span style="font-family: Calibri, Helvetica, sans-serif;font-size: 16px"><br></span></div><div><span style="font-family: Calibri, Helvetica, sans-serif"><span style="font-size: 16px">Well ... only if it is not a hierarchy of Magma collection classes. That would be more tricky. Then it's better to look out for compatibility with the standard/collection inspectors.</span></span></div><div><span style="font-family: Calibri, Helvetica, sans-serif"><span style="font-size: 16px"><br></span></span></div><div><span style="font-family: Calibri, Helvetica, sans-serif"><span style="font-size: 16px">Best,</span></span></div><div><span style="font-family: Calibri, Helvetica, sans-serif"><span style="font-size: 16px">Marcel</span></span></div><div class="mb_sig"></div><blockquote class='history_container' type='cite' style='border-left-style:solid;border-width:1px; margin-top:20px; margin-left:0px;padding-left:10px;'>
                        <p style='color: #AAAAAA; margin-top: 10px;'>Am 12.01.2022 14:36:58 schrieb Thiede, Christoph <christoph.thiede@student.hpi.uni-potsdam.de>:</p><div style='font-family:Arial,Helvetica,sans-serif'>

<div id="divtagdefaultwrapper" style="font-size: 12pt;color: #000000;font-family: Calibri,Helvetica,sans-serif" dir="ltr">
<p>Hi Chris, hi Marcel, hi al,</p>
<p></p>
<p><br>
</p>
<p>> I would say that #size being an expensive operation on a collection is quite surprising and thus not foreseeable in general.</p>
<p><br>
</p>
<p>+1</p>
<p><br>
</p>
<p></p>
<p>> <span>If Magma collections require a modification, then Magma can make an extension or offer its own Magma-specific inspectors.</span></p>
<p><span><br>
</span></p>
<p><span>+1</span></p>
<p><span><br>
</span></p>
<p>Chris, you could override #inspectorClass on your MagmaCollection and have it answer MagmaCollectionInspector, a subclass of CollectionInspector which overrides #labelString again. :-)</p>
<p><br>
</p>
<p>Another "hacky" solution without creating your own inspector would be a sender check in your #size implementation:</p>
<p><br>
</p>
<p>MagmaCollection >> #size</p>
<p>    (thisContext sender receiver isKindOf: Inspector) ifTrue: [^ nil].</p>
<p>    ^ self expensiveSize</p>
<p><br>
</p>
<p>Disclaimer: This will be likely noticeably slower, of course. :-)</p>
<p><br>
</p>
<p>---</p>
<p><br>
</p>
<p>> <span style="font-size: 12pt">I'm not sure, but Eliot says it's the way Proxy's are supposed to be done in Squeak so that ProtoObject can have no methods.</span></p>
<div><br>
</div>
<div>I am aware of two implementation strategies for proxies:</div>
<div><br>
</div>
<div><b style="font-size: 12pt">1. Transparent proxies/dynamic forwarding:</b><br>
</div>
<div><br>
</div>
<div>
<div>ProtoObject subclass: #MyProxy1</div>
<div><span style="white-space:pre"></span>instanceVariableNames: 'object'</div>
<div><span style="white-space:pre"></span>classVariableNames: ''</div>
<div><span style="white-space:pre"></span>poolDictionaries: ''</div>
<div><span style="white-space:pre"></span>category: ''</div>
<div><br>
</div>
<div><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;font-size: 16px">MyProxy1 </span>>> <span style="font-size: 12pt">doesNotUnderstand:
 aMessage</span>
<div><span style="font-size: 12pt;white-space: pre"></span><span style="font-size: 12pt">^ aMessage sendTo: object</span><br>
</div>
<div><span style="font-size: 12pt"><br>
</span></div>
<div><span style="font-size: 12pt">(aka "transparent proxies" or "dynamic forwarding")</span></div>
<div><span style="font-size: 12pt"><br>
</span></div>
<div><span style="font-size: 12pt">Additionally, you can insert any custom logic, e.g., treat certain messages in a special way, do logging, lazy initialization of the object, or anything else.</span></div>
</div>
</div>
<div><span style="font-size: 12pt">If you do not want to follow the proxy's forwarding logic but look into the private state of the proxy instance itself, you would use mirror primitives, i.e., "thisContext objectSize: myProxy" rather than "myProxy size".
 It is important to note that one should do this rarely because any overuse of mirror primitives prevents developers from customizing the behavior.</span></div>
<div><span style="font-size: 12pt"><br>
</span></div>
<div><span style="font-size: 12pt">I have used this kind of proxies in some projects and my overall experiences are pretty positive so far. Nevertheless, </span><span style="font-size: 12pt">here are some limitations with this approach:</span></div>
<div><span style="font-size: 12pt"><br>
</span></div>
<div><span style="font-size: 12pt">- ProtoObject is still not yet an empty class. For instance, stuff such as #<span>doOnlyOnce: or #scaledIdentityHash should be implemented on Object only. We should continue work on this in the Trunk. You can mitigate this
 by redefining these messages in your proxy and forwarding them yourself.</span></span></div>
<div><span style="font-size: 12pt"><span>- Some selectors, such as #class or #==, are special selectors and inlined by the compiler so that the bytecode does not actually trigger a method lookup. If performance did not matter, I would vote for disabling the inlining
 by default to resolve this limitation. See: <a href="http://lists.squeakfoundation.org/pipermail/squeak-dev/2021-November/217060.html" class="OWAAutoLink" id="LPlnk317923" previewremoved="true">http://lists.squeakfoundation.org/pipermail/squeak-dev/2021-November/217060.html</a></span></span></div>
<div>- Primitive methods do not resolve proxies automatically, i.e., #(1 2 3) at: (MyProxy1 for: 2) would have the primitive failed. My mitigation for this problem was to define an exclusion list for certain classes that should never be wrapped into a proxy,
 but this is not an ideal solution, of course. If the performance overhead is slow, I would support the introduction of a new pattern in the Trunk that tries to unwrap any proxy if a primitive failed. For instance, Object >> #at: could use a mirror primitive
 to find out whether the primitive failed for a proxy and then retry with "self at: index yourself" or something similar. I would actually love this to upgrade the potential of proxies to certain degree. :-)</div>
<div><br>
</div>
<div><b>2. Intransparent proxies:</b></div>
<div><b><br>
</b></div>
<div>You derive from Object or any domain-specific class and override/reimplement every relevant message yourself, for instance:</div>
<div><br>
</div>
<div>MyProxy2 >> #size</div>
<div>    ^ object size</div>
<div><br>
</div>
<div>The benefit is more control over the forwarded messages, but the disadvantages include the need to reimplement a potentially large protocol from all superclasses as well as the target object's class and maintain this list as both protocols change over
 time. This makes it less appealing and looks "unclean" and "dirty" to me.</div>
<div><br>
</div>
<div>If I understand you correctly, Magma currently uses intransparent proxies? :-)</div>
<div><br>
</div>
<div>Best,</div>
<div>Christoph</div>
<p></p>
<p><span><span><span></span></span></span></p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><span style="font-family: Calibri, sans-serif;color: #000000"><b>Von:</b> Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel<br>
<b>Gesendet:</b> Mittwoch, 12. Januar 2022 09:10:54<br>
<b>An:</b> squeak-dev<br>
<b>Betreff:</b> Re: [squeak-dev] The Inbox: Tools-ct.1101.mcz</span>
<div> </div>
</div>
<div>
<div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000;text-align: left" dir="ltr">
Hi Chris, hi all --
<div><br>
</div>
<div>> <span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">CollectionInspector is used for Magma's large MagmaCollections, which require a db access to retrieve the size</span></div>
<div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br>
</span></div>
<div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">CollectionInspector is optimized for Smalltalk collections. That's the only thing we can guarantee. If Magma collections require a modification, then Magma can make an extension or
 offer its own Magma-specific inspectors. Yet, it makes sense to always look out for such external projects to not break compatibility without reason. I would say that #size being an expensive operation on a collection is quite surprising and thus not foreseeable
 in general.</span></div>
<div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br>
</span></div>
<div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">Currently the default Inspector should not be used to look behind proxies. That's what the BasicInspector is for. If a proxy mimics morphs, than that normal inspector for such proxies
 should also be a MorphInspector. And so on.</span></div>
<div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br>
</span></div>
<div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">Best,</span></div>
<div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">Marcel</span></div>
<div class="mb_sig"></div>
<blockquote class="history_container" type="cite" style="border-left-style:solid;border-width:1px; margin-top:20px; margin-left:0px;padding-left:10px;">
<p style="color: #AAAAAA; margin-top: 10px;">Am 12.01.2022 00:52:20 schrieb Chris Muller <ma.chris.m@gmail.com>:</p>
<div style="font-family:Arial,Helvetica,sans-serif">
<div dir="ltr">
<div class="gmail_quote">
<div>Hi Christoph, </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div id="m_-8378222150661093537gmail-m_-4771741952269926656divtagdefaultwrapper" style="font-size: 12pt;color: rgb(0,0,0);font-family: Calibri,Helvetica,sans-serif" dir="ltr">
<p><span style="font-size: 12pt">I am not sure whether we can (or should) make the default inspector proxy-safe. Rather, IMHO the default inspectors should handle proxies transparently and display the underlying object.</span><br>
</p>
</div>
</blockquote>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div id="m_-8378222150661093537gmail-m_-4771741952269926656divtagdefaultwrapper" style="font-size: 12pt;color: rgb(0,0,0);font-family: Calibri,Helvetica,sans-serif" dir="ltr">
<p><span style="font-size: 12pt">For inspecting the implementation details of proxies, we have the BasicInspector, which is almost completely proxy-safe (the only exception I am aware of is a send to #isReadOnlyObject for the window label, for which we currently
 do not have a mirror primitive).</span></p>
</div>
</div>
</blockquote>
<div>Yes, in principle, it's impossible to argue against that.  "Backward-compatibility" for Magma is all I've got. </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div id="m_-8378222150661093537gmail-m_-4771741952269926656divtagdefaultwrapper" style="font-size: 12pt;color: rgb(0,0,0);font-family: Calibri,Helvetica,sans-serif" dir="ltr">
<p><span style="font-size: 12pt">> </span><span style="font-size: 12pt">#size is a provoking message.</span><br>
</p>
<p><span style="font-size: 12pt">And #printString, #</span><span style="font-size: 12pt">longPrintString, #perform:, #instVarNamed:, #basicSize, and all others existing sends are not? :-)</span></p>
</div>
</div>
</blockquote>
<div>They are, but not invoked until you interact with the Inspector.  Putting the #size in the title bar changes that behavior.<br>
</div>
<div><br>
</div>
<div>Also, it may be presumptuous to assume the collection being inspected is a SmalltalkCollection.  CollectionInspector is used for Magma's large MagmaCollections, which require a db access to retrieve the size..</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div id="m_-8378222150661093537gmail-m_-4771741952269926656divtagdefaultwrapper" style="font-size: 12pt;color: rgb(0,0,0);font-family: Calibri,Helvetica,sans-serif" dir="ltr">
<p><span style="font-size: 12pt">> </span><span style="font-size: 12pt">Magma's Proxy's anyway (which don't use the mirror-primitives but the old-school Proxy pattern)</span></p>
<p>Just out of interest, how would you implement a proxy using mirror primitives? :-)</p>
</div>
</div>
</blockquote>
<div>I'm not sure, but Eliot says it's the way Proxy's are supposed to be done in Squeak so that ProtoObject can have no methods.</div>
<div><br>
</div>
<div>Unfortunately, it would require rewriting a lot of low-level methods like Symbol>>#=  to be (to my knowledge) non-standard Smalltalk which, realistically, is not ever going to be done, and therefore I'm doubtful the dream of "transparent proxies" will
 ever, uh, materialize (no pun intended!  :)  ), which is unfortunate because that "dream" continues to be a Magma-killer (slowly by a thousand cuts).  Magma's Proxy's have worked well-enough for *applications* for many years, but lately developers seem to
 want "clean", "transparent" proxies and so even the standard old-school Gang-of-Four Proxy pattern remains broken since 5.3.</div>
<div><br>
</div>
<div>I hope I'm missing something and completely wrong about the above, but I don't think I am.  I admit I haven't had the time or inclination to try to re-inventing Magma's proxy system just to accommodate some abstract notions of purity.  I'm concerned with
 application of computer code to external, real-world purposes.</div>
<div><br>
</div>
<div> - Chris</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div></blockquote>
                                        </div></body>