Search code examples
smalltalkpharosqueakmonticello

Safely to declare and initialize a global variable in a monticello package?


How can you safely declare and initialize a global variable used by a Monticello package so you don't get errors during loading? Is doing

Smalltalk at: #VarName put: varValue

in a class-side "initialize" method of one of the package classes enough? (I would prefer not to use shared pools in this case.)


Solution

  • Yes, that's enough. Another option would be to use lazy initialization:

    ^ VarName ifNil: [ VarName := value ]
    

    I'm curious, why are you using a global variable? In my experience there are only very few cases which can't be solved without using global variables and it is my opinion that in most cases the use of a global variable is a hint for bad design.