From: David Vallner Date: 2006-02-13T07:51:00+09:00 Subject: Re: Struct creates non-standard classes D�a Nede�a 12 Febru�r 2006 21:48 Robert Klemme nap�sal: > 2006/2/12, Mark Volkmann : > > On 2/12/06, David Vallner wrote: > > > D�a Nede�a 12 Febru�r 2006 20:45 Mark Volkmann nap�sal: > > > > If Struct is a shorthand way for creating Classes, why don't objects > > > > created from those Classes have instance_variables? > > > > My issue is that I wanted to think of Struct as an alternate way of > > defining a class and that after doing so I could use it like any other > > class. > > You can. > > > However, classes created using Struct aren't the same as > > classes created in the "normal" way and because of that I have to > > remember when I use them how they differ. I've found one way in which > > they differ and don't know if there are others. > > IMHO you better get used to access instance variables through accessor > methods instead of directly - even inside another class. You can run > into numerous problems if you always directly access instance > variables. The fact that Ruby allows to do this (even from sub class > methods) does not mean that it's always the best thing to do. > > The fact that there are instance variables is a mere detail of the > implementation. If you stick with this basic OO usage pattern and make > accessing instance variables directly the exception instead of the > rule there is no difference in using Struct created classes and > "normal" classes. > Amen. I blame selfdot syndrome when using setters for people using instance attributes directly. I wonder if we're getting that shorthand I saw mentioned somewhere, if using accessors wasn't any longer than not using them, I expect a dramatic increase of their use internally. David Vallner