Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>Object subclass: Foo []</code> is not “usual” Smalltalk syntax, it's a recent addition designed to make it practical to code in files. Prior to that there was no dedicated syntax to declare class, since they would be created by a command in the image. Interpreting this code as you expected would be wrong for a couple reasons:</p> <ul> <li><p>First, if <code>subclass:</code> was a real message sent to <code>Object</code>, then <code>Foo</code> should resolve to something, which is not possible since it is just being declared. However, behind the scenes, the compiler does something similar <code>Object subclass: #Foo</code> where <code>#Foo</code> is a symbol for the name of a new class to be created. It would be possible to write all code like that, except then you could not use class names directly (since they don't exist yet when the code is read). You would have to do <code>(Smalltalk at: #Foo) new printNl</code> all over the place. So the whole form <code>Object subclass: Foo [ ]</code> is pure syntax that just declares that this class should be created, and does not mean that at this moment a message should be sent to <code>Object</code>, etc</p></li> <li><p>Second, you don't want to create classes in the middle of an algorithm and send them messages immediately, that would be pretty ugly as a development practice. Note that classes have to be registered in the system so that the browser can display them, that the compiler can automatically recompile dependancies, that the version control can record them, etc. Also, what if your code accidentally runs this twice? Should you get a second class Foo and forget about the previous one? So, typically, only the compiler, browser, and other meta-programming tools create new classes, and only at the programmer's request.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload