Category:Smalltalk: Difference between revisions

Line 353:
By convention, global and namespace variables are to be used for classes only. As in every other language, it is considered extremely bad style to use globals for anything else.
They are created by telling the namespace to add a binding, as in <lang smalltalk>Smalltalk at:#Foo put:<something></lang>
The binding's value can be retrieved by asking the namespace: <lang smalltalk>x := Smalltalk at:#Foo</lang> or simply by referring to the binding by name (if the corresponding namespace is visible in the scope of the code): <lang smalltalk>x := Foo</lang>
As seen above, the global named <tt>Smalltalk</tt> refers to the Smalltalk namespace, which is globally visible. (technicallyTechnically, there is a binding to itself) inside the Smalltalk namespace, and the Smalltalk namespace is visible everywhere by default.
 
====Class Variables (Statics)====
Anonymous user