``` Object subclass: #Test instanceVariableNames: 'var1 var2' classVariableNames: '' package: 'MyTest' I was struggling with instanceVariableNames even though they show up under methods. Perhaps I'm just slow, but it wasn't until last night when I was reading on Object Pascal and there was an example: type TProjector = class(TTelevision) Brightness, Temperature: Integer; procedure Focus(Length: Single); end; Then it finally clicked with me that "var1" and "var2" under instance variables in Smalltalk would be like the method "Focus" in Object Pascal. Is that correct, or am I still not getting it? ```
Hi, Instance variables are nicely explained in Pharo by Example in chapter 6.4 pp 89 http://books.pharo.org/. Best wishes, Tomaz
Iâm far from being an expert but I think you misunderstood. Are you familiar with the concept of instance variables and having trouble with the syntax or do you need some help on the concept of instance variables ? Assuming you are familiar with the concept, here are some explanation about the syntax: in the Smalltalk example you gave, instance variables donât show up in methods; this example is just the Smalltalk way to declare a class with two instance variables var1 and var2 (no method is declared here). The Pascal example would translate to: ``` TTelevision subclass: #Television instanceVariableNames: 'Brightness Temperature' classVariableNames: '' package: 'MyTest' ``` Methods like Focus are declared in a separate way. If you are new to Smalltalk and OOP, I suggest you take the Pharo MOOC (https://www.fun-mooc.fr/en/courses/live-object-programming-pharo/) which will help you a lot. HTH,\ Mathieu
If you are coming from a Pascal background, instance variables of an object correspond to fields of a record. They are called instance variables - because they are variables - that belong to INSTANCES of a class (object) as opposed to class variables - which are variables - that belong to the CLASS itself and are thus shared by all instances. Other programming languages use terminology like slots, fields, data members, ... The keyword 'instanceVariableNames:' is used because the string that follows contains the names of the variables, not the variables themselves. One thing to note is that in Smalltalk all instance variables (fields, slots, whatever) are PRIVATE. These are not the names of accessor methods, although there may be accessor methods with the same spelling. On Tue, 7 Dec 2021 at 05:32, <danhunfeldz@mail.com> wrote:
Object subclass: #Test instanceVariableNames: 'var1 var2' classVariableNames: '' package: 'MyTest'
I was struggling with instanceVariableNames even though they show up under methods. Perhaps I'm just slow, but it wasn't until last night when I was reading on Object Pascal and there was an example:
type TProjector = class(TTelevision) Brightness, Temperature: Integer; procedure Focus(Length: Single); end;
Then it finally clicked with me that "var1" and "var2" under instance variables in Smalltalk would be like the method "Focus" in Object Pascal. Is that correct, or am I still not getting it?
Am 08.12.2021 um 22:56 schrieb Richard O'Keefe <raoknz@gmail.com>:
Other programming languages use terminology like slots, fields, data members, ...
The keyword 'instanceVariableNames:' is used because the string that follows contains the names of the variables, not the variables themselves.
To experience that go into settings (under the âPharoâ menu item) search for âslotsâ. You will get this If you open a new system browser it looks like this Collection << #SmallDictionary slots: { #keys . #values . #size }; tag: 'Dictionaries'; package: 'Collections-Unorderedâ which resembles the slots representation better. Hope this helps and not raise confusion even more. Norbert
participants (5)
-
danhunfeldz@mail.com -
duboismathieu_gaas@yahoo.fr -
Norbert Hartl -
Richard O'Keefe -
Tomaž Turk