I don't quite understand some syntax seen in books

Eric Arseneau eric at ericsworld.com
Sun May 13 19:46:27 UTC 2001


> I have looked over some smalltalk tutorials and am now looking at
> Kent Beck's
> "Smalltalk Best Practice Patterns".
>
> I have come across some code fragments that I do not understand, such as:
>
> Controller>>controlActivity
> 	self controlInitialize.
> 	self controlLoop.
> 	self controlTerminate.
>
> What the heck is the '>>' between 'Controller' and 'controlActivity'?
>
> Is this simply an indication that controlActivity is a method in class
> Controller?  If so, what kind of method, class or instance?

This "syntax" is a standard way of describing methods in text.  The part
preceeding the ">>" is the behavior to which, the selector, follows the
">>", belongs to.  Here are a couple of examples

1)
	Controlller>>controlActivity
		...
This is an instance method called controlActivity, belonging to the class
Controller as an instance method.

2)    Controller class>>iAmAClassMethod
		...
This is a class method belong on the class side of Controller.

This "syntax" comes from the way file out works and is a short form. If you
look at a file-out, you would see something like

	!Controller methodsFor: 'some category'!
	method1
		self doSomething!

	method2
		self doSomethingElse! !

The first "!", the first character of the line (this is key), tells the file
in process that a source code chunk of some kind is comming.  The file in
process then extracts everything up to the second "!" and evaluates the
expression.  The result of this expression should be something like a
ClassCategoryReader (see implementors of "methodsFor:").  This reader then
gets given the stream being filed in and is supposed to do its processing
until it reaches an empty chunk (a chunk with nothing in it other than
whitespace, in the above example its the "! !".  The first "!" terminates
the method2 source, the second "!" identifies an empty chunk.

In order to talk about code in text form, we usually ignore the category and
extra pieces and use the form discussed above.  The basis for most things
Smalltalk is to use Smalltalk expressions to describe itself.  So in your
questions above, is it a class method, think of evaluating the code before
the ">>".  If the result is a class, then the method is an instance method,
if the result is a meta class, then the method is a class method.  Remember,
evaluating an expression like "Controller" yields the class, which means
that doing anything to that will affect the class and its instances.
Evaluating an expression like "Controller class" yields the meta class of
Controller, which means that doind anything to that will affect the class
side of Controller.

Probably more detail and more grammatical errors than were necessary to
explain this, but there it is :)





More information about the Squeak-dev mailing list