
On Friday 24 October 2003 23:10, Phillip J. Eby wrote:
At 01:39 PM 10/24/03 -0700, Zack Weinberg wrote:
class foo: A = 1 # these are class variables B = 2 C = 3 ... thought A, B, C were instance variables, although it wasn't hard to understand why they aren't.
A, B, and C *are* instance variables. Why do you think they aren't?
They're _accessible AS_ instance attributes (self.B will be 2 in a method), but they have the same value in all instances and to _rebind_ them you need to do so on the class object (you can bind an instance variable with the same name to shadow each and any of them, of course).
What good does declaring the set of instance variables *do*? This seems
It decreases productivity -- that's the empirical result of Prechelt's study and the feeling of people who have ample experience with both kinds of language (cfr Robert Martin's well-known blog for an authoritative one, but my own experience is quite similar). If you subscribe to the popular fallacy known as "lump of labour" -- there is a total fixed amount of work that needs to be done -- it would follow that diminishing productivity increases the number of jobs available. Any economist would be appalled, of course, but, what do THEY know?-)
to be more of a mental comfort thing than anything else. I've spent most of my career in declaration-free languages, though, so I really don't understand why people get so emotional about being able to declare their variables.
Most of MY work has been with mandatory-declaration languages, and my theory is that a "Stockholm Syndrome" is in effect (google for a few tens of thousands of explanations of that syndrome).
and there is no other way in the language?
Actually, there are a great many ways to implement such a thing. One way
For instance variables, yes. Fewer for class variables (you need a custom metaclass). None for module variables (also misleadingly known as 'global' ones) nor for local variables. Alex