=== Top of the Swiki === Attachments ===

Method


Methods are the "meat" of the code.

Basically, a method represents a named list of statements to be executed.

The method name may define parameters, that is objects to be sent to it, for use inside the method.

It's very important to remember that the method is executed in the reciever's context. That means that in it (and only in it) you can access the objects instance variables and call inherited behavior (via super).

A little about how methods are represented.
A method has lots of responsibilities - it must be very efficient to execute, because that is what Squeak is doing most of the time. It must easy for humans to read and edit, because that's what Squeak users do much of the time. Lastly, it must be represented in a form that is natural and makes it simple to run algorithms like pretty printing (automatic indentation) on it.

All three roles are essential, and the requirements for each conflict with the other two. Since it's impossible to find one or two representations with all properties, Squeak simply uses each of the three and converts between them as needed.

The use that occurs most often is being run by the system, so that has to happen very fast, without taking time for translation. Thus method dictionaries hold CompiledMethods, which are exquisitely tuned to one purpose - run fast.

The form that the users edit, arguably the form that most precisely captures their intentions, is that of text - simple strings. For this reason, it's the text form that is stored in an external code database (the source+changes file) and that is used to pass code to other users (by filing out code).

It's sad, but all this means that the most natural and precise way to encode the essence of the method, which is it's Parse Tree, simply isn't kept around. It's created when the system parses text (when us users enter new code), or when the system decompiles a CompiledMethod (when the source code is missing), used for whatever purpose, and discarded. It's power and utility are that it's (relatively) very easy to do things with parse trees, including generation of either of the other representations, running metrics that tell you of properties of the code such as it's complexity, or transforming them as in the RefactoringBrowser.