Class-level readers and writers

ts wrote:

Well, if @_var make reference to what was initially,
wrongly, called “private instance variable” then renamed in
“class local variable” then it’s private to the instance

Just for the record the starting point (started by nobody
else but yourself:-) of a long, probably definite thread on
the subject was [ruby-talk:49849]. The original post to get
the ball rolling was Christian’s post [ruby-talk:49161].

/Christoph

Hi –

···

On Mon, 1 Dec 2003, ts wrote:

My least favorite of all of the proposed changes is definitely the
@var/@_var thing. It means that, for the first time, the concept of
an instance variable will not be completely unified. At the very
least, I don’t think something should be called an “instance variable”
if it isn’t private to the instance. (And then there’s that
underscore… :slight_smile:

Well, if @_var make reference to what was initially, wrongly, called
“private instance variable” then renamed in “class local variable” then
it’s private to the instance

I’m not sure I follow entirely – which one was wrongly called that?

(I’m just going by Matz’s slide, where “instance variable” covers the
case where it’s visible to subclasses, which are different instances.)

David


David A. Black
dblack@wobblini.net

Oh right. I keep forgetting those because I wish they would go away
:slight_smile: (Sorry Matz, if you're reading; I just personally don't like magic
behavior depending on the name of a variable, in any language.)

Implement it and just wait for error from standards libraries :-))

Guy Decoux

I'm not sure I follow entirely -- which one was wrongly called that?

Initially @_var were called "private instance variable", but it's stupid
because an instance variable is private to the instance.

They were renamed "class local variable" to say that you can access this
instance variable *only* in the class where this variable was created

Guy Decoux

David A. Black wrote:

Well, if @_var make reference to what was initially,
wrongly, called
“private instance variable” then renamed in “class local variable”
then it’s private to the instance

I’m not sure I follow entirely – which one was wrongly called that?

In the original discussion what we call “class local” instance variables
today (I actually think I coined that term - in connection - ups -
analogy - to block local variables:-) was originally called “private”
instance variables.

/Christoph

OK… but then they’re “class local variables”, right, not “class local
instance variables”? (since they’re visible inside method definitions).

(I think I missed or have forgotten a thread somewhere…)

David

···

On Mon, 1 Dec 2003, Christoph wrote:

David A. Black wrote:

Well, if @_var make reference to what was initially,
wrongly, called
“private instance variable” then renamed in “class local variable”
then it’s private to the instance

I’m not sure I follow entirely – which one was wrongly called that?

In the original discussion what we call “class local” instance variables


David A. Black
dblack@wobblini.net

David A. Black wrote:

In the original discussion what we call “class local” instance
variables

OK… but then they’re “class local variables”, right, not
“class local instance variables”? (since they’re visible
inside method definitions).

Yes, I just wanted to be “über” correct and added
the collectively swallowed “instance” part - since
they are “kind_of” an instance variable.

/Christoph

Hi –

···

On Mon, 1 Dec 2003, Christoph wrote:

David A. Black wrote:

In the original discussion what we call “class local” instance
variables

OK… but then they’re “class local variables”, right, not
“class local instance variables”? (since they’re visible
inside method definitions).

Yes, I just wanted to be “über” correct and added
the collectively swallowed “instance” part - since
they are “kind_of” an instance variable.

Although… I think that if a variable’s scope is a superset of
instance scope (which would include class local variables and global
variables), then it really isn’t an instance variable (although it may
well serve to do the same things as one in many situations).

Not to quibble – just reasoning it out in anticipation of change :slight_smile:

David


David A. Black
dblack@wobblini.net

David A. Black wrote:

In the original discussion what we call “class local” instance
variables

OK… but then they’re “class local variables”, right, not “class
local instance variables”? (since they’re visible inside method
definitions).

Yes, I just wanted to be “über” correct and added the collectively
swallowed “instance” part - since they are “kind_of” an instance
variable.

Although… I think that if a variable’s scope is a superset

Nope it’s a subset of today’s instance variables …

of instance scope (which would include class local variables
and global variables), then it really isn’t an instance
variable (although it may well serve to do the same things as
one in many situations).

Not to quibble – just reasoning it out in anticipation of change :slight_smile:

/Christoph

Hi –

David A. Black wrote:

In the original discussion what we call “class local” instance
variables

OK… but then they’re “class local variables”, right, not “class
local instance variables”? (since they’re visible inside method
definitions).

Yes, I just wanted to be “über” correct and added the collectively
swallowed “instance” part - since they are “kind_of” an instance
variable.

Although… I think that if a variable’s scope is a superset

Nope it’s a subset of today’s instance variables …

I thought that a class local variable was going to be visible to the
Class object and its instance:

class C
@_v = 1
puts @_v # 1
def m
puts @_v # 1
end
end

which would mean it has a wider scope than an instance variable:

class C
@v = 1
puts @v # 1
def m
puts @v # nil (self’s @v, not C’s @v)
end
end

?

David

···

On Tue, 2 Dec 2003, Christoph wrote:


David A. Black
dblack@wobblini.net

I thought that a class local variable was going to be visible to the
Class object and its instance:

well, what difference do you make between @_v and @@v ?

Guy Decoux

Hi –

I thought that a class local variable was going to be visible to the
Class object and its instance:

well, what difference do you make between @_v and @@v ?

From Matz’s description I’m not sure I see any difference; they’re
both described as “local to the class/module”.

I seem to be failing to understand the new rules. The only thing I’m
sure of is that if a variable is directly visible to two different
'self’s, then it is not an instance variable. Please explain the
rest :slight_smile:

David

···

On Tue, 2 Dec 2003, ts wrote:


David A. Black
dblack@wobblini.net

From Matz's description I'm not sure I see any difference; they're
both described as "local to the class/module".

Well, except that one is described in the slide 13 and the other in the
slide 20. Perhaps it's important

Guy Decoux

Hi –

···

On Tue, 2 Dec 2003, ts wrote:

From Matz’s description I’m not sure I see any difference; they’re
both described as “local to the class/module”.

Well, except that one is described in the slide 13 and the other in the
slide 20. Perhaps it’s important

OK, I’m officially being stupid. Can someone please explain?

David


David A. Black
dblack@wobblini.net

Don’t even bother; it has dawned on me that I have been forgetting
that not all variables are created at class scope. Well, I was right
about one thing: I’m being stupid :slight_smile:

David

···

On Tue, 2 Dec 2003, David A. Black wrote:

Hi –

On Tue, 2 Dec 2003, ts wrote:

From Matz’s description I’m not sure I see any difference; they’re
both described as “local to the class/module”.

Well, except that one is described in the slide 13 and the other in the
slide 20. Perhaps it’s important

OK, I’m officially being stupid. Can someone please explain?


David A. Black
dblack@wobblini.net

Hi,

···

In message “Re: Class-level readers and writers” on 03/12/02, “David A. Black” dblack@wobblini.net writes:

From Matz’s description I’m not sure I see any difference; they’re
both described as “local to the class/module”.

Well, except that one is described in the slide 13 and the other in the
slide 20. Perhaps it’s important

OK, I’m officially being stupid. Can someone please explain?

@_v is an instance variable whose scope is limited to the
class/module. @@v is a class variable, which is kinda like global
variable whose scope is limited to the class/module.

						matz.