Please use accessors!
Carl Gundel
morphic at hotmail.com
Mon Aug 2 02:49:51 UTC 1999
>From: Alan Lovejoy <sourcery at pacbell.net>
>Reply-To: squeak at cs.uiuc.edu
>Subject: re: Please use accessors!
> > ** Original Sender: "Carl Gundel" <morphic at hotmail.com>
> > >From: Alan Lovejoy <sourcery at pacbell.net>
> > >Reply-To: squeak at cs.uiuc.edu
> > <big snip>
> > >8. Given the above, I would avoid being dogmatic on this
> > >issue. I think the fact that so many good Smalltalk programmers
> > >still access instance variables directly, and that code that commits
> > >this "sin" has lasted unchanged for so long, should cause one to
> > >at least question whether or not it's all that sinful.
> > <snip>
> >
> > Thanks for the brain dump Alan! :-)
> >
> > I understand the pragmatics of this issue well, but I feel compelled to
>make
> > a counterpoint about the above. Code that accesses ivars directly can
>be
> > brittle. In particular, code which uses both direct access and accessor
> > methods on the same ivars can behave in unpredictable ways. Sometimes
>such
> > code survives for a very long time because it is brittle and hard to
> > understand, and no one wants to touch it for fear of breaking it.
> >
> > I tend to defer writing code which accesses ivars directly until
>performance
> > tuning time. I wish I never had to write such code because it hurt the
> > maintainability and extensibility of my design, but I live in the real
>world
> > (oh Bah!).
> >
> > Thanks again!
> >
> > -Carl
>
>Poorly designed code will be brittle. But I am convinced that blaming
>direct iVar access as the culprit is an oversimplification.
Okay, but I didn't say that direct ivar access was the sole culprit of
brittle code. Writing code for myself, I sometimes don't use accessors, but
when working on a team I usually automatically generate them.
It isn't possible to pin down any "always right" programming practices. In
my own experience, next year I won't completely agree with everything I
might say today. ;-)
-Carl
_______________________________________________________________
Get Free Email and Do More On The Web. Visit http://www.msn.com
More information about the Squeak-dev
mailing list
|