A puzzle for the New Year

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

A puzzle for the New Year

Trygve
Hi,
I had to dive into  the deeper regions of Smalltalk when I was preparing BabyIDE for Monticello. I needed to specialize a class  fileOut method:
BB5aMoneyTransferContext>>fileOutOn: aFileStream moveSource: moveSource toFile: fileIndex initializing: aBool
    super fileOutOn: aFileStream moveSource: moveSource toFile: fileIndex initializing: aBool.
    <my own additions>
This works, but the fileOutOn:moveSource:toFile:initializing:-method is defined in class Class which is not a superclass of BB5aMoneyTransferContext. So super does not refer to the superclass! What's going on?
--------------------------------------------------
There are two essential object structures in Smalltalk: The instantiation tree and the class inheritance tree. They are independent but intertwined as described in chapter 16 of the Blue Book. It's pretty complicated in the general but fairly obvious in this concrete example.

Smalltalk is all about objects, not classes.  I used my Smalltalk Reverse Engineering (SRE) tool and produced the attached object diagram. The notation in the diagram is
  • a rectangle represents an object 
  • the object's name is [<oop>] : <class name>
  • a line represents a link. An 'instanceOf' relationship is marked /self class; an inheritance relationship is marked superclass.
The diagram shows that the answer to the puzzle is one 'instaceOf' relationship followed by four  'superclass' relationships. The departure from the usual is that while most class objects are instances of their own  Metaclass. ProtoObject is an exception. It has no superclass, but its metaclass has. It is class Class. Add to this that when an object receives a message, it goes to its class to find the corresponding method. [1224]:MoneyTransferContext  receives the super fileout message. The VM goes to  the superclass of its class, [3253]:Metaclass and looks for the required method in its methodDict. It doesn't find it and continues up the superclass chain until it finds it in [1254]:Class class . Straight forward, isn't it.
 
I hope you enjoy this dive into the innards of Smalltalk and wish you all A Happy New Year!
--Trygve



Collaboration-[1224] BB5aMoneyTransferContext # BB5aMoneyTransferContext class.1.gif (27K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: A puzzle for the New Year

David T. Lewis
On Fri, Jan 02, 2015 at 12:01:24PM +0100, Trygve Reenskaug wrote:

> Hi,
> I had to dive into  the deeper regions of Smalltalk when I was preparing
> BabyIDE for Monticello. I needed to specialize a class /fileOut /method:
>
>    BB5aMoneyTransferContext>>fileOutOn: aFileStream moveSource:
>    moveSource toFile: fileIndex initializing: aBool
>         super fileOutOn: aFileStream moveSource: moveSource toFile:
>    fileIndex initializing: aBool.
>         <my own additions>
>
> This works, but the /fileOutOn:moveSource:toFile:initializing:/-method
> is defined in class /Class/ which is not a superclass of
> /BB5aMoneyTransferContext/. So /super /does not refer to the superclass!
> What's going on?
> --------------------------------------------------
> There are two essential object structures in Smalltalk: The
> instantiation tree and the class inheritance tree. They are independent
> but intertwined as described in chapter 16 of the Blue Book. It's pretty
> complicated in the general but fairly obvious in this concrete example.
>
> Smalltalk is all about objects, not classes.  I used my /Smalltalk
> Reverse Engineering (SRE)/ tool and produced the attached object
> diagram. The notation in the diagram is
>
>  * a rectangle represents an object
>  * the object's name is [<oop>] : <class name>
>  * a line represents a link. An 'instanceOf' relationship is marked
>    //self class/; an inheritance relationship is marked /superclass/.
>
> The diagram shows that the answer to the puzzle is one 'instaceOf'
> relationship followed by four  'superclass' relationships. The departure
> from the usual is that while most class objects are instances of their
> own  Metaclass. ProtoObject is an exception. It has no superclass, but
> its metaclass has. It is class Class. Add to this that when an object
> receives a message, it goes to its class to find the corresponding
> method. [1224]:MoneyTransferContext  receives the super fileout message.
> The VM goes to  the superclass of its class, [3253]:Metaclass and looks
> for the required method in its methodDict. It doesn't find it and
> continues up the superclass chain until it finds it in [1254]:Class
> class . Straight forward, isn't it.
>
> I hope you enjoy this dive into the innards of Smalltalk and wish you
> all A Happy New Year!
> --Trygve

Very nice illustration. It's interesting that you were able to generate
the diagram automatically and produce a very clear diagram to show the
relationships.

Dave


Reply | Threaded
Open this post in threaded view
|

Fwd: [squeak-dev] A puzzle for the New Year

Nicolas Cellier
In reply to this post by Trygve

---------- Forwarded message ----------
From: Nicolas Cellier <[hidden email]>
Date: 2015-01-04 11:30 GMT+01:00
Subject: Re: [squeak-dev] A puzzle for the New Year
To: The general-purpose Squeak developers list <[hidden email]>


A picture is worth a few dozen of words indeed.

I'm pretty sure I saw a browser showing the whole metaclass hierarchy in the past which also might be helpfull to better understand these corners, but I just don't remember where exactly (st-80 v2.3?).

2015-01-02 12:01 GMT+01:00 Trygve Reenskaug <[hidden email]>:
Hi,
I had to dive into  the deeper regions of Smalltalk when I was preparing BabyIDE for Monticello. I needed to specialize a class  fileOut method:
BB5aMoneyTransferContext>>fileOutOn: aFileStream moveSource: moveSource toFile: fileIndex initializing: aBool
    super fileOutOn: aFileStream moveSource: moveSource toFile: fileIndex initializing: aBool.
    <my own additions>
This works, but the fileOutOn:moveSource:toFile:initializing:-method is defined in class Class which is not a superclass of BB5aMoneyTransferContext. So super does not refer to the superclass! What's going on?
--------------------------------------------------
There are two essential object structures in Smalltalk: The instantiation tree and the class inheritance tree. They are independent but intertwined as described in chapter 16 of the Blue Book. It's pretty complicated in the general but fairly obvious in this concrete example.

Smalltalk is all about objects, not classes.  I used my Smalltalk Reverse Engineering (SRE) tool and produced the attached object diagram. The notation in the diagram is
  • a rectangle represents an object 
  • the object's name is [<oop>] : <class name>
  • a line represents a link. An 'instanceOf' relationship is marked /self class; an inheritance relationship is marked superclass.
The diagram shows that the answer to the puzzle is one 'instaceOf' relationship followed by four  'superclass' relationships. The departure from the usual is that while most class objects are instances of their own  Metaclass. ProtoObject is an exception. It has no superclass, but its metaclass has. It is class Class. Add to this that when an object receives a message, it goes to its class to find the corresponding method. [1224]:MoneyTransferContext  receives the super fileout message. The VM goes to  the superclass of its class, [3253]:Metaclass and looks for the required method in its methodDict. It doesn't find it and continues up the superclass chain until it finds it in [1254]:Class class . Straight forward, isn't it.
 
I hope you enjoy this dive into the innards of Smalltalk and wish you all A Happy New Year!
--Trygve







Reply | Threaded
Open this post in threaded view
|

Re: A puzzle for the New Year

Nicolas Cellier


2015-01-07 18:25 GMT+01:00 Nicolas Cellier <[hidden email]>:

---------- Forwarded message ----------
From: Nicolas Cellier <[hidden email]>
Date: 2015-01-04 11:30 GMT+01:00
Subject: Re: [squeak-dev] A puzzle for the New Year
To: The general-purpose Squeak developers list <[hidden email]>


A picture is worth a few dozen of words indeed.

I'm pretty sure I saw a browser showing the whole metaclass hierarchy in the past which also might be helpfull to better understand these corners, but I just don't remember where exactly (st-80 v2.3?).

Oh I just see it now, still there in Squeak trunk after all these years!!!

Select a class, select the class side button, and operate the pop up menu 'show hierarchy'. It's not as powerfull as a Hierarchybrowser, but is already someting.
 

2015-01-02 12:01 GMT+01:00 Trygve Reenskaug <[hidden email]>:
Hi,
I had to dive into  the deeper regions of Smalltalk when I was preparing BabyIDE for Monticello. I needed to specialize a class  fileOut method:
BB5aMoneyTransferContext>>fileOutOn: aFileStream moveSource: moveSource toFile: fileIndex initializing: aBool
    super fileOutOn: aFileStream moveSource: moveSource toFile: fileIndex initializing: aBool.
    <my own additions>
This works, but the fileOutOn:moveSource:toFile:initializing:-method is defined in class Class which is not a superclass of BB5aMoneyTransferContext. So super does not refer to the superclass! What's going on?
--------------------------------------------------
There are two essential object structures in Smalltalk: The instantiation tree and the class inheritance tree. They are independent but intertwined as described in chapter 16 of the Blue Book. It's pretty complicated in the general but fairly obvious in this concrete example.

Smalltalk is all about objects, not classes.  I used my Smalltalk Reverse Engineering (SRE) tool and produced the attached object diagram. The notation in the diagram is
  • a rectangle represents an object 
  • the object's name is [<oop>] : <class name>
  • a line represents a link. An 'instanceOf' relationship is marked /self class; an inheritance relationship is marked superclass.
The diagram shows that the answer to the puzzle is one 'instaceOf' relationship followed by four  'superclass' relationships. The departure from the usual is that while most class objects are instances of their own  Metaclass. ProtoObject is an exception. It has no superclass, but its metaclass has. It is class Class. Add to this that when an object receives a message, it goes to its class to find the corresponding method. [1224]:MoneyTransferContext  receives the super fileout message. The VM goes to  the superclass of its class, [3253]:Metaclass and looks for the required method in its methodDict. It doesn't find it and continues up the superclass chain until it finds it in [1254]:Class class . Straight forward, isn't it.
 
I hope you enjoy this dive into the innards of Smalltalk and wish you all A Happy New Year!
--Trygve