Meta-concept (was: Confusion over basic Array new:)

Mark Wai mwai at ibm.net
Thu Sep 24 01:33:36 UTC 1998


Warning:   This is a long note and you might find the content completely
useless.


At 11:41 AM 9/17/98 -0700, you wrote:
>guzdial at cc.gatech.edu wrote:
<snip>
> So where's the method that is being called on this message?
>
>You should be searching through
>	Array class
>	ArrayedCollection class
>	SequentialCollection class
>	Collection class
>and	Object class
>
>Then you find that Object class's superclass is not nil, since its a
>Class, but Class.  So the search is actually:
>
>	Array class
>	ArrayedCollection class
>	SequentialCollection class
>	Collection class
>	Object class
>	Class
>	ClassDescription
>	Behavior (voila!)
>	Object
>
<snip>


Based on my experience in the past on teaching people on the concept of
metaclass, with the aid of the very nice diagram from the purple book, most
of the time people still don't understand it.  Even for the students who
claimed they understand it, I later found out that they (most of them)
actually don't understand it.  But I don't want to give up on getting more
people to understand one of the most basic meta-concept of all meta-concepts
because I think this meta space is one of the most interesting and useful
area in computer science.

I think some of the difficulties on understanding this meta-relationship is
due to the fact that Smalltalk has implicit metaclasses and hidden
metaclasses hierarchy (which I can't do anything).   And I noticed that a
good portion of people just can not "see through" certain thing.  So no
matter how hard I try to illustrate the meta-circularity and the metaclasses
hierarchy, I didn't have a lot of success.

Therefore, I started to go with another approach.  Instead of having the
students to "see through" this meta-relationship, I have them "experiment"
it first, and then reconstruct this relationship by themselves.  So, I
abandoned all the diagrams and drawing that I have done before.  And
surprisingly, the result is pretty good and that's why I wanted to share here.

To use the original question as an example, to find out where the >>new
method is implementated when send this message to the Array object.  I asked
them to do the following:

1)  Find out what class this receiver belongs to because the class of the
receiver dictate what it can understands.  Simple enough:

        Array class

2)  Find out if the resulting object from 1) implements the method or not.
If not, go up the hierarchy and start search from its superclass.  In step
2), the following constraint must be applied:

If the resulting object is a metaclass, keep sending >>superclass until the
resulting object is not a metaclass.

P.S.  In order to find out whether an object is a metaclass or not,  inspect
the resulting object to see whether the inspector labelled with 'Metaclass'
or not.  Alternatively, print the resulting object and if the string has the
word 'class' as the last word, it is a metaclass.

Hence, 

Array class superclass       ---> is a metaclass, so keep sending >>superclass
Array class superclass superclass  --> is a metaclass, so keep sending >>
superclass

until           Array class superclass superclass superclass superclass
superclass

which answers Class.  Since Class is explicit (i.e. not a metaclass), they
can start searching in the browser to see if Class implements >>new or not.
Since it is not so keep going up to its superclass.

Finally    Array class superclass superclass superclass superclass
superclass superclass superclass

which answer the class Behavior and bingo, method located.

3)  From each message send, write down the named class and draw the
hierarchy from bottom up.

So Array class   

                Array class

Array class superclass
                
                SequenceableCollection class
                        Array class

until

Array class superclass superclass superclass superclass superclass
superclass superclass

                Behavior
                   ClassDescription
                        Class
                --------------------------------------
                           Object class
                               Collection class
                                   SequenceableCollection class
                                        ArrayedCollection class
                                            Array class
                ---------------------------------------
                              

Now the students can see the implicit as well as the explicit hierachy.  But
most importantly, they draw each level by themselve by 'experiement' it.
Obviously, the above hierachy, though illustrated the parallel hierarchies,
is not complete because it skips one of the most important class in question
- Metaclass that is.

Therefore,,

4)  Reintroduce the classic purple book diagram to the student.  Amazingly,
after the student can 'acutally' find out the answer by experimenting it
instead of spinning through the pointers in the diagram, they have a much
better appreciation and understanding.   At least, they understand that
there are actually exist a parallel hidden meta-hierarchy which could not be
seen by a standard browser.  Last but not the least, they understood that
the location of such method is not by magic(well, in a sense it is :-)), it
is actually through perfect inheritance mechanism.

Anyway, I just wanted to share my experience with this community and thanks
for reading (if you are reading this far).


--
Mark Wai
Wator Innovision
mailto: mwai at ibm.net or:[ mwai at frontiersa.com] 
__





More information about the Squeak-dev mailing list