From: Tom Sawyer Date: 2002-08-12T21:51:23+09:00 Subject: Re: ambiguity backtrack - accessors and persistent locals On Fri, 2002-08-09 at 13:30, Dave Thomas wrote: > This is an interesting issue: should internal users go via the setter > method or access the instance variable directly. Clearly it depends on > the circumstances, but I often find myself writing accessors that do > things such as lazy evaluation, or which set dirty flags for > persistent objects, and where I really do need to go via the method > form. For those times, it's nice to have a shortcut, but it isn't > something I'd fight hard for... :) i'd like to refocus on this aspect of the ambiguity thread. from what's been posted thus far on the topic, it would seem it is best to always use the accessor methods when they exist. i hanker to bet many of us do not do this. and i think this has to do with the fact that the @variables are more convenient, due to the extra thoguht that must go into determining when self must be used (albiet small), and the fact that @ is shorter than self. other reasons? so your idea for the . shortcut may be very helpful in encouraging better programming along these lines. currently ruby allows for space to exist between the reciever, the dot, and the message call, but i imagine it would be short work to adjust, and very rare to cause any code breakage. yet, i start to wonder, if using getter and setter methods is really how instance variables should be effected in OOP, and not forgetting kents discussion of "minimizing" the use of @ and @@ via accessor methods, persistent local variables make worthy of consideration. a persitent local variable is simply a variable whose value is not lost from one call to the method it resides in to the next. quick psuedo-example: def x(n) persist :x x = x + n end puts x(10) # --> 10 puts x(20) # --> 30 -- ~transami