the pickaxe defines Principle of Least Surprise as “things work the way
you expect them to, with very few special cases or exceptions.” i know
this doesn’t necessarily mean “things work the way you expect them in
other languages”, but i notice that ruby seems to surprise many people
with regard to class variables.
may i suggest that we pick a new term for ruby’s “class variables” in
the documentation? “class & subclass variable”, “classdown variable”,
“shared class variable”, …
even the downloadable pickaxe book has this in the “Classes, Objects,
and Variables” chapter:
“Class variables are private to a class and its instances.”
the pickaxe defines Principle of Least Surprise as “things work the way
you expect them to, with very few special cases or exceptions.” i know
this doesn’t necessarily mean “things work the way you expect them in
other languages”, but i notice that ruby seems to surprise many people
with regard to class variables.
may i suggest that we pick a new term for ruby’s “class variables” in
the documentation? “class & subclass variable”, “classdown variable”,
“shared class variable”, …
i’m guessing from those names, that your surprise is that class
variables get inherited…
why is this surprising? class methods get inherited, why shouldn’t class
variables?
even the downloadable pickaxe book has this in the “Classes, Objects,
and Variables” chapter:
“Class variables are private to a class and its instances.”
perhaps they should add “and any other classes that inherit that it” for
clarity’s sake.
i’m guessing from those names, that your surprise is that class
variables get inherited…
why is this surprising? class methods get inherited, why shouldn’t
class variables?
i’m mostly concerned with terminology. when people wants “class
variable”, they actually want “instance variable of class” in ruby.
which do you want, instance variables or class variables? they’re both
inherited by subclasses, just as both kinds of methods are. there is
only one instance of each class definition, and hence only one
instance of class variables and class methods. unless you redefine them
in the subclass, the ascentor’s class methods will be used.
···
On Wednesday, January 22, 2003, at 08:26 , David Garamond wrote:
^^^^^^^^^^^^^^^^^^^^^^^^^^
class instance variable?
This is AFAIK the standard terminology:
class A; @@a = 1; end # class variable
class A; def a; @a = 1; end; end # instance variable
class A; @a = 1; end # class instance variable
···
On Thu, Jan 23, 2003 at 10:26:39AM +0900, David Garamond wrote:
Justin White wrote:
i’m guessing from those names, that your surprise is that class
variables get inherited…
why is this surprising? class methods get inherited, why shouldn’t class
variables?
i’m mostly concerned with terminology. when people wants “class
variable”, they actually want “instance variable of class” in ruby.
–
_ _
i’m mostly concerned with terminology. when people wants “class
variable”, they actually want “instance variable of class” in ruby.
which do you want, instance variables or class variables? they’re both
inherited by subclasses, just as both kinds of methods are. there is
only one instance of each class definition, and hence only one
instance of class variables and class methods. unless you redefine them
in the subclass, the ascentor’s class methods will be used.
as mauricio pointed out, i was talking about “class instance variable”
(instance variable @var that is declard directly under the class
definition, not under method definition). is this somehow inherited to
subclasses too like a class variable (@@var)?
i’m mostly concerned with terminology. when people wants “class
variable”, they actually want “instance variable of class” in ruby.
^^^^^^^^^^^^^^^^^^^^^^^^^^
class instance variable?
This is AFAIK the standard terminology:
class A; @@a = 1; end # class variable
class A; def a; @a = 1; end; end # instance variable
class A; @a = 1; end # class instance variable
sorry, i was just using matz’ terminology [ruby-talk:16538]
class Foo @foo = :meep
@@bar = :moop
end
class Bar < Foo
p @foo
p @@bar
end
class Baz < Foo
def test
p @foo
p @@bar
end
end
Baz.new.test
tim@marvin:~$ ruby b.rb
nil
:moop
nil
:moop
tim@marvin:~$
Tim Bates
···
On Fri, 24 Jan 2003 12:12 am, David Garamond wrote:
as mauricio pointed out, i was talking about “class instance variable”
(instance variable @var that is declard directly under the class
definition, not under method definition). is this somehow inherited to
subclasses too like a class variable (@@var)?
(umm, my second ‘me too’ posting in 2 days, what’s happening to me?)
···
On Thu, Jan 23, 2003 at 10:44:14PM +0900, David Garamond wrote:
Mauricio Fernández wrote:
i’m mostly concerned with terminology. when people wants “class
variable”, they actually want “instance variable of class” in ruby.
^^^^^^^^^^^^^^^^^^^^^^^^^^
class instance variable?
This is AFAIK the standard terminology:
class A; @@a = 1; end # class variable
class A; def a; @a = 1; end; end # instance variable
class A; @a = 1; end # class instance variable
sorry, i was just using matz’ terminology [ruby-talk:16538]