Newbie q

Lex Spoon lex at cc.gatech.edu
Sat Sep 27 11:47:19 UTC 2003


Brian Brown <rbb at techgame.net> wrote:

> The principal difference is whether you know beforehand if a variable 
> is likely to be used and want to save space/resources if it won't. I 
> typically use Lazy Initialization for simple instance vars like strings 
> and numbers and even Collections, but use constructors and initialize 
> methods for more complex objects that I know will be used.
> 

Well there's a third place.  If you create a bunch of instances and
*then* add the variable, you might use lazy initialization so that you
don't have to recreate your objects.  This goes doubly if instances of
the class have been saved in people's images.  Recreating everyone's
Morphic World's, for example, could be a chore.

Anyway, that said, it seems to be a matter of taste.  What does it
matter if you are very careful to always initialize variables, versus
always being careful to use variables with lazy-initialization style
check for nil?  So long as you know which invariant is being used, it
all seems fine to me.  Granted, when I see a variable set to nil
nowadays, I have used Smalltalk enough to automatically realize it might
signify a variable with no special meaning, as opposed to a variable
that has no meaning at all.  So a lot of this is about people's
expectations.  That is, it's part of the culture.


Lex



More information about the Squeak-dev mailing list