From: "David A. Black" Date: 2005-07-04T12:57:50+09:00 Subject: Re: class variable leading a double life Hi -- On Sun, 3 Jul 2005, Devin Mullins wrote: > James Edward Gray II wrote: > >> If you want it to be the same variable in both places, you need a class >> variable: >> >> class Test >> @@var = 0 >> >> ... >> >> James Edward Gray II > > OK, now I'm confused. I had thought that class variables were just instance > variables of the Test object, but it seems that the case is much weirder than > that. (Why?) Actually the case is *less* weird than that :-) It comes down to: every object can have instance variables (including Class objects), and class variables are a completely separate matter. The confusion, I think, arises from the visual similarity (@ and @@), which suggests that there's some relation between the two. Then discussion proceeds as to how to reconcile them, or which should become more like the other, etc. -- which are really solutions in search of a problem. This confusion arises a lot. It's perhaps the main reason I would like to see class variables disappear in 2.0. They make it much harder for people to understand that classes can have instance variables, and that in turn interferes with understanding the whole instance variable concept as well as the "a class is itself an object" concept. David -- David A. Black dblack@wobblini.net