Newbie q

Matej Kosik kosik at decef.elf.stuba.sk
Fri Sep 26 12:52:32 UTC 2003


On Fri, Sep 26, 2003 at 09:25:32AM +0200, Brent Pinkney wrote:
> >
> > anInstanceVar
> > anInstanceVar ifNil: [
> > anInstanceVar _ someInitializationCode.
> > ].
> > ^ anInstanceVar
> >
> This is more terse:
> 
> anInstanceVar
> 
> 	^ anInstanceVar ifNil: [ anInstanceVar := someInitializationCode ]
 
Someone might prefer this approach. I have seen this approach regularly
used in the code generated by VisualWorks GUI builder and (to my
disappointment) also in some random places in Morphic classes.


  StringMorph>>fontToUse

whose name should certainly be

  StringMorph>>font

(but that is not the point of the discussion)

I do not like it. The trivial method which should do nothing more
but return the value of the appropriate instance variable is spoiled
by some superfluous stuff.

I always initialize instance variables in "constructors".

I didn't see that ifNil: practise anywhere within the Purple Book.
Fortunatelly the method Point>accessing>x does not look like this:

  ^x ifNil: [x := 0]

but thankfully like this

  ^x

I like it.

Although the fact that the #new method is not overloaded
there (to initialize the `x' and `y' instance variables to some
default values (0,0) is a little bit contradictory.
-- 
Matej Kosik <http://altair.dcs.elf.stuba.sk/wiki/Main/MatejKosik>
ICQ: 300133844



More information about the Squeak-dev mailing list