While protoyping in a "live" system like Pharo, you often may add a new
instance variable to existing object,
the value of which is "nil" and may break the associated behaviour you next
add.
To deal with that you either have to sprinkle ifNils: around your code,
or alternatively do it in one location with lazy initialization.

So in general, lazy initialization is good for prototyping.
Once you're past prototyping there might be some advantage to refactoring
away from lazy initialization.

cheers -ben




On 29 May 2018 at 23:49, sergio ruiz <sergio....@gmail.com> wrote:

> If a model has a list of things.. such as a user that can/may have lots of
> pets, are there any real benefits to initializing the list of pets lazily?
>
> like:
>
> self pets := OrderedCollection new.
>
> vs.
>
> pets
>  pets ifNil: [self pets: OrderedCollection new]
>  ^ pets
>
> thanks!
>
> ----
> peace,
> sergio
> photographer, journalist, visionary
>
> Public Key: http://bit.ly/29z9fG0
> #BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV
> http://www.codeandmusic.com
> http://www.twitter.com/sergio_101
> http://www.facebook.com/sergio101
>

Reply via email to