Tim vs. Accessors

Ron Teitelbaum Ron at USMedRec.com
Sun Oct 7 02:57:47 UTC 2007


Hi Blake,

I know I shouldn't respond to this, I've spent enough time arguing this in
person to know that both sides have very valid arguments and strong
opinions.  You know I just can't resist.

I create accessors and mutators for all instance variables.  I also create
fake senders for performed methods with comments that point developers to
where the methods are performed.  Why?  Because everything you can do to
help a developer understand what you did and why helps.  

Now I also try very hard to not use accessors and mutators outside the
context of the object.  It doesn't always work out that way.  I almost
always create instance creation methods.  I really do not support 

MyClass new foo: bar; yourself 

type creation from some other object.  I prefer 

MyClass class >> createForFoo: aBar ...

I do this because it makes it much easier to trace a class and to figure out
how to use that class.

I know Tim said only create accessors and mutators for those ivars that
should be exposed external to the object, but I disagree.  The benefits to
clarity and traceability outweigh the potential abuse.  

Happy coding!!

Ron Teitelbaum
President / Principal Software Engineer
US Medical Record Specialists




> -----Original Message-----
> From: Blake
> Hey, all,
> 
> 	If I may quote the esteemed Mr. Rowledge:
> 
> "Please, please, don't get in the habit of willy-nilly making accessors
> for every instance variable. All you're doing that way is opening the door
> to writing C code."
> 
> 	I believe the issue here is encapsulation, which I think we can
> uncontroversially agree upon as a good thing.
> 
> 	However, I've always tried to take encapsulation as far as I can,
> including using accessors as far as possible inside the object itself.
> I've saved myself a fair bit of work over the years by doing so. (After
> all, the benefits accrued by encapsulation to clients of an object are not
> excluded from the object itself.)
> 
> 	To answer Tim's plea, I would point out that by default, I make said
> accessors private. But of course, Smalltalk doesn't have a private
> directive. Some would say, you can have private methods, you just have to
> designate them as such, and others respect them (or not) at their own
> peril.
> 
> 	I would submit, then, that accessors are no more or less opening-
> the-door
> to C code than any other presumed private method.
> 
> 	Thoughts?
> 
> 	===Blake===





More information about the Squeak-dev mailing list