Newbie q

Martin Drautzburg martin.drautzburg at web.de
Fri Sep 26 06:57:23 UTC 2003


Phil Hudson <phil.hudson at iname.com> writes:

> Hmm. This prevents us from following a widely-accepted "best practice" in
> programming: always initialize every variable as soon as it comes into
> scope. Isn't this a Really Really Bad Thing?

Squeak warns you when you use an uninitialized *local* variable.

For using instance variables I frequently use lazy initializing like

anInstanceVar
        anInstanceVar ifNil: [
                anInstanceVar _ someInitializationCode.
        ].
        ^ anInstanceVar

This of course assumes that you don't read anInstanceVar directly in
any other place but only thru this method (which isn't a bad idead
anyways).



More information about the Squeak-dev mailing list