Stupid Question?

tim Rowledge tim at
Wed Jan 16 18:58:50 UTC 2008

> Richard Eng wrote:
>> I'm not finding this to be true. I have a class #GSAssignmentList.  
>> It has
>> instance variable #clientId and accessor #clientId:. I do the  
>> following:
>>    self call: (GSAssignmentList new clientId: aValue)
>> In the #initialize method for GSAssignmentList, I write to the  
>> Transcript:
>>    Transcript cr; show: 'RKE: clientId = ', clientId asString.
>> It shows 'nil'.

Of course it does. You've simply written the code incorrectly.
GSAssignmentList new
	creates a new GSAssignmentList instance with all instance variables  
set to nil.
	sends #initialize to that new instance.
	returns the new instance
... and then....
(new instance) clientId: aValue
	presumably sets the clientId instance variable to aValue. Do remember  
that you don't need to name them the same. Nothing wrong with having a  
method named #fred: that sets the value of an instvar named wilma.

So if you report the value of clientId as part of an #initialize  
method, what value would you expect? How about 'nil'? Unless you  
actually explicitly set clientId in the initialize method before you  
show it on the Transcript how could you expect it to be anything else?

Smalltalk syntax is very simple and concise
left to right
parentheses limit local scope as in most syntaxes

tim Rowledge; tim at;
Oxymorons: Business ethics

More information about the Squeak-dev mailing list