> I don't mind if you don't quote me in full, but chopping paragraphs in
> half is bound to lead to confusion.
Sorry, that was because I was already lost after the first part.
The original full paragraph was:
> I thought you might say that, but there's really no reason why you
> should insist on defining class instance variables in the class method
> scope. It's a nested scope, and Smalltalk has no inner classes, so
> there's no reason to treat it the same as the outer scope.
And now I see what you probably meant. Did you mean
"defining class instance variables" instead of *class variables*
"in the class method scope"?
If so, there is a good reason, and it is that class variables
are misused 99% of the time. Class variables are *global* variables
visible to a hierarchy and, as such, they should be used as little as
possible. When implementing a singleton, for example, what you *really*
want is a uniqueInstance class-instance variable.
The name of class variables is all wrong. I would call them "class pool
variables", or "class global variables", and I would say that "class-instance
variables" are the "real" class variables.
Class variables should be used mostly to include constant objects
(as was the case for pool dictionaries before they became a more general
"import namespace" mechanism), so, it makes sense to me to use a syntax
like this to define them:
Class name: Character extends: Object [
| value |
...
Cr := Character value: 13.
Lf := Character value: 10.
Table := Character initializeConversionTable
]
This is similar to how you would write these initializations in a
Character class>>#initialize method.
In addition, it's not necessary that the class scope be a nested scope
(if this bothers you, please tell me). You can perfectly well write:
Class ref: Character class [
del [ ^Character value: 127 ]
]
(I hope that, with "ref:" as the keyword, it is clearer that the correct
precedence is "Class ref: (Character class)" and not "(Class ref: Character)
class". If you wish to suggest an alternate keyword, again, please do).
Paolo
_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk