Personally I prever to avoid long lazy initializations, so I have it nice and 
tidy in a single method.

MyClass>>#property
        ^ property ifNil: [ property := self bar collect: #food ]

If I want to initialize the value in a separate method (typically for testing 
or reuse), then I prefer to avoid state mutation there and instead I return the 
result.

MyClass>>#property
        ^ property ifNil: [ property := self createNewProperty ]

MyClass>>createNewProperty
        "I won't touch property instance variable here, just create a new value 
and return it"
        ^ self bar collect: [ :e | e drink ]


> an initializationMethod returning the value instead of the receiver is a code 
> smell to me.

For this reason I tend to name such methods createNewX, initializeX says to me 
"only mutate state and return self"

Peter

Reply via email to