2

It seems that creating a new subclass in Squeak is done by sending a message to the super class:

Object subclass: #Boolean
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'Kernel-Objects'

Where can I look at the implementation of this method? I can't find it in Object's nor ProtoObject's class methods list.

1
  • Try looking in Behavior. Commented Mar 6, 2020 at 20:38

1 Answer 1

6

Yes it is an ordinary message. The implementation is in the class called Class. You can find its implementation by selecting the message name in any class definition (like the one you posted in the question) and invoke the "implementors of it" action (Cmd-m, or in the pop up menu if you hold shift while clicking).

You will find that it delegates to ClassBuilder, where you can see how new classes come into existence.

Note that you send the message to the class Object, not to an instance of Object. That's why you did not find a method in Object or ProtoObject. You would rather have to look up the method in Object class, which is the metaclass of Object, and it inherits from Class.

8
  • 1
    Thanks for the answer. I see that ClassBuilder is created using the same message. So what came first, the chicken or the egg? 😂
    – Artium
    Commented Mar 7, 2020 at 22:16
  • @mstram The name of the method is actually subclass:instanceVariableNames:classVariableNames:poolDictionaries:category: (the whole selector you see when you look at a class definition).
    – JayK
    Commented Oct 25, 2023 at 11:55
  • @mstram There is no method that is simply called subclass: (at least not in the base system), there is only the longer one (and a few more variants of it, but these are distinct methods). In the code that you posted above, the whole name of the method with all the keywords is present, so I don't quite understand what you mean with "it jumps to the longer version". It just sends the message with the long name, it doesn't send subclass: without the rest of the name. Can you explain in more detail how you interact with the code? Maybe that will explain how you got your impression.
    – JayK
    Commented Oct 26, 2023 at 8:15
  • Or maybe there is a misunderstanding about the language: in the code snippet myObject foo: 42 bar: 13 the message foo:bar: is sent to the object myObject with the arguments 42 and 13. There is no message foo: involved here. All the keywords belong together to form the method name, so to speak. It is just the same with that long-winded subclassing message.
    – JayK
    Commented Oct 26, 2023 at 8:17
  • I get it now. I was mis-reading the "subclass:" / " instanceVariableNames:'' ... as being separate methods, when in fact (obviously) they are all part of the same method clause (very beginner level Smalltalk here).
    – mstram
    Commented Oct 26, 2023 at 9:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.