I met William Cook last year at OOPSLA 09 (renamed SPLASH as of this year) whose presentation and subsequent blog entry "objects use recursion everywhere" reminded me of work I did years ago on a pictorial representation of how recursion occurs in objects due to 'self' and 'inheritance' (leading to a colleague at the time commenting on how it reminded them of a Klein Bottle).
The basic idea is that an object is a rod of methods surrounded by an environment of variable bindings as shown in cross section on the left. All methods can reference 'self' which can be shown as a hole that is drilled through the methods rod:
At this stage, the 'self hole' is waiting for an object to be supplied. Any object that conforms to the required interface can be supplied. Recursion occurs because the object that is used to fill the hole is the object itself...
...this is achieved by grabbing the top of the object, pulling it round and feeding the object into its own 'self hole'...
grab the top ... ...pull it round...
...feed the object in and keep going...
This trick can be be used to explain super too. Instead of onw hole there are two holes:
Inheritance means fitting rods together:
This idea was used to define a semantics for Smalltalk. The details can be found here but beware, it is a scanned document and is over 60MB. This slightly less esoteric (but a similarly large scanned document) set of notes on OOP and recursion is a useful introduction.
Posting on Bluesky, and other thoughts on social media
-
With the recent uptick in tech activity on Bluesky, I've decided that I
will start posting there in addition to my current locations.
I've also put toget...
1 day ago
No comments:
Post a Comment