POLS (with one case: "class variable")

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.”

···


dave

the pickaxe defines Principle of Least Surprise as "things work the way
you expect them to, with very few special cases or exceptions."

Well, for ruby POLS is better defined by

"things work the way matz expect them to"

:-)))

Guy Decoux

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.

-Justin White

just6979@yahoo.com
http://tin.2y.net/
AIM: just6979

···

On Wednesday, January 22, 2003, at 05:09 , 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.

···


dave

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.

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:

– dave

^^^^^^^^^^^^^^^^^^^^^^^^^^
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.

_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

<|ryan|> I don’t use deb
u poor man
netgod: heh
apt-get install task-p0rn

Justin White wrote:

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)?

···


dave

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] :slight_smile:

···


dave

It would seem not:

tim@marvin:~$ cat b.rb

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)?


tim@bates.id.au

Me too :slight_smile: [19535]

(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] :slight_smile:


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

The documentation is in Japanese. Good luck.
– Rich $alz