<div dir="ltr">Hi Facundo,<div> When I show that in my classes, I implement it from scratch using TDD in a class that simulates a VM. Doing so decouples the implementation from what Cuis does, as that is not really how the method lookup is implemented. It also allows you to implement how the method lookup changes when sending the message to super and it gets really interesting when testing for sending #doesNotUnderstand: and not getting in an infinite loop when it is not found. </div><div> Anyway, this is just a suggestion that may help and may avoid this change just in case.</div><div><br></div><div>Hernan.</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, Sep 21, 2026 at 2:18 PM Facundo Javier Gelatti via Cuis-dev <<a href="mailto:cuis-dev@lists.cuis.st">cuis-dev@lists.cuis.st</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello!<br><br>I've been experimenting with some improvements for the messages we use to simulate the method lookup (i.e. Behavior>>#lookupSelector:), motivated by the OOP courses I teach (where I like to show the implementation of the method lookup). I figured the changes might be of interest for integration on the Cuis base image, so I'm sending some proposals!<br><br>The changes I propose are twofold:<br>1. Change sets 1-2x are a proposal to have a new #lookupSelector:ifAbsent: message, to be able to specify what to do when the selector is not found (instead of always returning nil). The change set labelled 1 introduces it, and the ones labelled as 2x use it in some of the methods we already have. I tried to name the files as descriptively as possible, to help during review.<br>2. Change set 3 is a proposal for a new implementation of #lookupSelector:ifAbsent:. The implementation I propose avoids using a while loop, it's a recursive implementation which I find a bit less imperative (and, might I say, "more object-oriented"). Surprisingly, the implementation has also better performance compared with the current one (it runs about 30% faster)¹.<br><br>To be able to evaluate the second proposal, I attach some useful scripts:<br>* Some benchmarks for the average case and two "worst cases".<br>* A (partial) correctness test, which asserts that the methods found by both implementations are the same (traversing all the methods in the image).<br>* A script to try it out with very deep class hierarchies.<br>These scripts should be evaluated manually in a workspace, while switching between the two implementations.<br><br>I hope you find these changes, if not useful, at least interesting!<br>Cheers!<br>Facu<br><br>______<br>¹ Of course, being a recursive implementation, it limits the class hierarchy depth by the stack size. But since the depth of all inheritance hierarchies on the image is less than 20, and having a deep inheritance hierarchy is already a design smell, we might consider taking the design + performance improvement. Also, currently the maximum stack size is limited by RAM (at least by default), so the change works with very large hierarchies too (see the attached <a href="http://very_deep_hierarchy_test.st" target="_blank">very_deep_hierarchy_test.st</a> script).</div>
-- <br>
Cuis-dev mailing list<br>
<a href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a><br>
<a href="https://lists.cuis.st/mailman/listinfo/cuis-dev" rel="noreferrer" target="_blank">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><br>
</blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div style="font-size:small"><div dir="ltr"><div dir="ltr"><div style="font-size:12.8px"><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span style="font-size:small"><font size="2"><span style="font-weight:normal"><span style="font-weight:bold">Hernán Wilkinson</span><br>Agile Software Development, Teaching & Coaching</span></font></span></span></strong></span></div><div style="font-size:12.8px"><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span style="font-size:small"><font size="2"><span style="font-weight:normal">Phone: +54-011</span></font></span></span></strong></span><font face="tahoma, sans-serif" size="2">-4893-2057</font></div><div style="font-size:12.8px"><strong style="font-family:tahoma,sans-serif;font-size:xx-small"><span style="font-size:8pt"><span style="font-size:small"><font size="2"><span style="font-weight:normal">Twitter: @HernanWilkinson</span></font></span></span></strong></div><div style="font-size:12.8px"><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span style="font-size:small"><font size="2"><span style="font-weight:normal">site: <a href="http://www.10pines.com/" style="color:rgb(17,65,112)" target="_blank">http://www.10Pines.com</a></span></font></span></span></strong></span></div><div style="font-size:12.8px"><font face="tahoma, sans-serif"><span style="border-collapse:collapse">Address: Alem 896</span></font>, Floor 6, Buenos Aires, Argentina</div></div></div></div></div></div></div></div>