3

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.)

1 Answers1

3

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.

Max Leske
  • 5,007
  • 6
  • 42
  • 54
  • 1
    That lazy initialization will work, but the variable will still be undeclared. So in any case, to get a proper global variable, you have to declare it. – codefrau Mar 23 '15 at 14:00