2017-08-05 19:21 GMT-03:00 Peter Uhnak <i.uhnak@gmail.com>:
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"
I like this approach very much, it makes the accessor code concise and separates the implementation of the property creation. Thank you! Esteban A. Maringolo