On 04/10/16 03:37, CodeDmitry wrote:
> "static" variables in Pharo outlive their Playground call! There is no such thing as a "static" method or "static" variable in Smalltalk. At least not in the Java sense. In most languages a static method is simply a function attached to a class (because there is no other place to put it). But it does not imply any meaning to this/self. It's similar for variables ... because Global Variables are frowned upon most programmers simply attach them to a class - making them "static". That's different in Smalltalk. In Smalltalk /every method is an instance method/! "Regular methods" are defined by the instance's class and executed within an instance context. "Class methods" are defined by the instances's *meta*class and also executed in an instance context - only that the instance at that point is the class itself! Because there is a 1:1 relationship between the class (defining the instance behavior) and it's meta-class (defining the class behavior) the Smalltalk Browser provides a unified view. E.g. if you create a class in the class browser you'll also create it's metaclass. The code you see when browsing "the instance side" is the method dictionary of the class. If you switch to "the class side" in the class browser you are essentially browsing the method dictionary of it's metaclass! It's a bit more complex for variables. Ignoring regular instance variables a "class variable" is defined by a class and is shared with all it's subclasses. E.g. a class hierarchy, where only one of the subclasses is used for a Singleton at a time could use a class variable "Current". A "class instance variable" on the other hand does not share it's value with subclasses. E.g. the class name and it's method dictionary could be candidates for class inctance variables - i.e. they are unique per class - not per hierarchy! IMHO this implementation of instances/classes/metaclasses is very different from the "static" stuff used today. Take a look here (especially Chapter 5 in the Blue Book) for more details: http://esug.org/data/Articles/Columns/EwingPapers/cvars&cinst_vars.pdf http://stephane.ducasse.free.fr/FreeBooks/BlueBook/Bluebook.pdf CU, Udo |
"static" the worst name for a class variable. On Tue, 4 Oct 2016 at 09:26, Udo Schneider <[hidden email]> wrote: On 04/10/16 03:37, CodeDmitry wrote: |
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
|
Free forum by Nabble | Edit this page |