He he Ben - I was just coming over here to ask something similar … It also struck me that a method that initialises a class variable should rerun when saved, as the mystery of class side #initialize and when its actually sent can be a bit overwhelming.
These days, we have all of the hooks to do this well don’t we? I guess the issue comes down to how far you have to go if there are method dependencies etc. So yeah - maybe a pragma to make the intent clear might be a nice way to go. As it stands (and where I’m sure this thread comes from) - I think the clarity of: MyVar ifNil: [MyVar := self bigInitialisation] makes it a bit more obvious that its a lazy initialisation and you have to re-run it (and I cheat with an example like: “MyClassVar := nil. MyClass myClassVarAccessor >>>”) But I wonder if the lazy initialisation approach is the favoured one anyway - and am curious what others think (but still agree with Ben that class initialised vars should work better in this day and age). Tim > On 4 Mar 2019, at 02:46, Ben Coman <b...@openinworld.com> wrote: > > In relation to developing sample solutions for an Exercism exercise, the > following observation was made about class initialization... > >> class is initialized on load - and not when you modify it - so this can be >> very confusing for users > > My first thought was to wonder if Quality Assistant could track whether a > class initialize method had been run after it was modified, > and display alerts. > > Alternatively, I wonder if a reasonable pattern would be to couple class-side > lazy initialization > with a pragma to reset a variable when the method is saved... > > MyClass class >> referenceData > <onSaveResetVariable: ReferenceData> > ^ ReferenceData := ReferenceData ifNil: [ 'reference data' ] > > cheers -ben