On Jun 4, 2007, at 19:40 , subbukk wrote:
On Sunday 27 May 2007 9:44 pm, Bert Freudenberg wrote:
There is a difference between "class variables" (which are like "static" variables in other systems, so they get their fare share of use) and "class instance variables" (very rarely used indeed). You see "class instance variables" only when you switch the browser to the class side. "Class instance variables" have a different value in each subclass and are private to the class-side. Hence they are not global and have lower-case names.
Thank you for explaining this in detail. I missed the fact that instance variables listed by browser on the class side are different from those on the instance. If I understood this correctly: (class instance) variables - variables global to all objects instantiated from a class
This sounds more like "class variables".
class (instance variable) - instance variable of the class (treated as an object and therefore visible only to its methods and methods in its subclasses).
I don't think that is correct - what do you mean by "treated as an object"? I may be repeating myself, but *everything* is "treated as an object", because it is.
There really is only a difference between local and global variables. Local vars are lowercase by convention and local to an object instance ("instance variables") or a method activation ("temporary variables", "arguments"). There are special byte codes to access them. Global variables are uppercase by convention and are actually Associations (key->value pairs) held in dictionaries known to the compiler, and the Association gets stored as literal in a CompiledMethod. Their "globalness" differs in what dictionary ("variable pool") they live in - the one called "Smalltalk", or the "classPool" inst var of classes (these are "class variables"), or in shared pools (pools that are listed in the "sharedPool" class inst var, or whatever other dictionaries where given to the compiler (like "References" for etoys scripts).
BTW, I used the code below to inspect classes with explicit CIVs: (Smalltalk values select: [ :c | (c isKindOf: Class) and: [c class allInstVarNames size > 13 ] ]) collect: [ :d | { d . d class allInstVarNames size} ]
but this gave me classes that inherit them too. Is there a way to tease out classes that *define* CIVs?
Smalltalk allClasses select: [:ea | ea class instVarNames size > 0]
So one of them is Beeper. Just do a "Beeper inspect" to see its class inst vars, or to see which superclass defines what, do:
Beeper class withAllSuperclasses collect: [:ea | ea -> ea instVarNames]
an OrderedCollection( Beeper class->#('default') Object class->#() ProtoObject class->#() Class->#('subclasses' 'name' 'classPool' 'sharedPools' 'environment' 'category') ClassDescription->#('instanceVariables' 'organization') Behavior->#('superclass' 'methodDict' 'format') Object->#() ProtoObject->#() )
- Bert -