[ruby2] will '@@' disapear in ruby2?

Hello there!

I remember I have read some post of Matz saying '@@' will disapear in ruby2. Have I read well or am I in some sort of confusion once again? Will '@@' really disapear in ruby2 or not?

Thanks in advance,
Lionel Thiry

Lionel Thiry wrote:

I remember I have read some post of Matz saying '@@' will disapear in ruby2. Have I read well or am I in some sort of confusion once again? Will '@@' really disapear in ruby2 or not?

AFAIK it will only change in that it will have a better defined role. (Definition time scope based sharing between instances and the class itself, AFAIK.)

Hi --

Hello there!

I remember I have read some post of Matz saying '@@' will disapear in ruby2. Have I read well or am I in some sort of confusion once again? Will '@@' really disapear in ruby2 or not?

I think you may have read my post saying that if I could change one
thing about Ruby, it would be to get rid of @@var :slight_smile: Matz is going
to change it, so that it's more truly class-specific, though I would
still rather just ask classes to have their own instance variables and
not have this other thing that's *almost* like that, but not quite.
I've seen a lot of confusion arising from the @/@@ similarity, and
I've never thought it's worth it.

Anyway, the short answer as far as I know is "no" :slight_smile:

David

···

On Tue, 15 Mar 2005, Lionel Thiry wrote:

--
David A. Black
dblack@wobblini.net

Hi,

I remember I have read some post of Matz saying '@@' will disapear in ruby2.

Did I? I remember I admitted it's ugly.

Have I read well or am I in some sort of confusion once again? Will '@@' really
disapear in ruby2 or not?

I have no plan to remove it right now.

              matz.

···

In message "Re: [ruby2] will '@@' disapear in ruby2?" on Tue, 15 Mar 2005 22:55:48 +0900, Lionel Thiry <lthiryidontwantspam@skynetnospam.be> writes:

]
     by skynet.be (unknown) with NNTP id 129042
     for <comp.lang.ruby>;
Received: from Usenet via a Usenet to mail gateway located at
     TU-Berlin.DE. This service provided as a courtesy to the
     ruby-talk mailing list. If this message is SPAM, its ultimate
     origin is Usenet, not this gateway program. All subscribers
     to the ruby-talk mailing list agree to receive the Usenet
     postings made to comp.lang.ruby via this gateway. Please see
     http://www.ruby-lang.org/ruby-talk-usenet-policy.html\.
X-From-Usenet: see Received: header above.
X-rubymirror: yes

David A. Black wrote:

Hi --

Hello there!

I remember I have read some post of Matz saying '@@' will disapear in ruby2. Have I read well or am I in some sort of confusion once again? Will '@@' really disapear in ruby2 or not?

I think you may have read my post saying that if I could change one
thing about Ruby, it would be to get rid of @@var :slight_smile:

Maybe, I can't remember who post it. But I remember Matz saying he made a big mistake and regret it. Or was it someone who tried to act as him?

Matz is going
to change it, so that it's more truly class-specific, though I would
still rather just ask classes to have their own instance variables and
not have this other thing that's *almost* like that, but not quite.
I've seen a lot of confusion arising from the @/@@ similarity, and
I've never thought it's worth it.

I'm currently explaining the differences to a friend. As he mainly comes from java and C++ background, it is a big pain.

Anyway, the short answer as far as I know is "no" :slight_smile:

Too bad! :slight_smile:

···

On Tue, 15 Mar 2005, Lionel Thiry wrote:

--
Lionel Thiry

]
     by skynet.be (unknown) with NNTP id 129044
     for <comp.lang.ruby>;
Received: from Usenet via a Usenet to mail gateway located at
     TU-Berlin.DE. This service provided as a courtesy to the
     ruby-talk mailing list. If this message is SPAM, its ultimate
     origin is Usenet, not this gateway program. All subscribers
     to the ruby-talk mailing list agree to receive the Usenet
     postings made to comp.lang.ruby via this gateway. Please see
     http://www.ruby-lang.org/ruby-talk-usenet-policy.html\.
X-From-Usenet: see Received: header above.
X-rubymirror: yes

Yukihiro Matsumoto wrote:

Hi,

>I remember I have read some post of Matz saying '@@' will disapear in ruby2.

Did I? I remember I admitted it's ugly.

Maybe I'm in confusion but... I remember you said you made a mistake with '@@', in response to a post saying '@@' violates some fundamental OO principles, or something like that, and should had never existed.

>Have I read well or am I in some sort of confusion once again? Will '@@' really >disapear in ruby2 or not?

I have no plan to remove it right now.

              matz.

Thanks a lot for the answer!

···

In message "Re: [ruby2] will '@@' disapear in ruby2?" > on Tue, 15 Mar 2005 22:55:48 +0900, Lionel Thiry <lthiryidontwantspam@skynetnospam.be> writes:

--
Lionel Thiry

I do like having them. In fact, they are globals, wrapped in the
namespace of a class/module. There are situations when you need such a
beast, and it's better than an explicit global... and better than using a
container as a constant (just because constans don't like being
reassigned), that's really ugly.

My problem is that you can't really access them from the outside, unless
accessor method are set up. By "from the outside" I mean that from code
which is not in the scope of a "class/module Foo ... end" thingy. Does
anyone know, eg, how to define a class variable in a nameless class?

Csaba

···

On 2005-03-15, Lionel Thiry <lthiryidontwantspam@skynetnospam.be> wrote:

Anyway, the short answer as far as I know is "no" :slight_smile:

Too bad! :slight_smile:

Hi --

Anyway, the short answer as far as I know is "no" :slight_smile:

Too bad! :slight_smile:

I do like having them. In fact, they are globals, wrapped in the
namespace of a class/module. There are situations when you need such a
beast, and it's better than an explicit global... and better than using a
container as a constant (just because constans don't like being
reassigned), that's really ugly.

My problem is that you can't really access them from the outside, unless
accessor method are set up. By "from the outside" I mean that from code
which is not in the scope of a "class/module Foo ... end" thingy.

You can always use class_eval or instance_eval. I think part of the
point is that they're specific to that scope.

Does anyone know, eg, how to define a class variable in a nameless
class?

Do you mean like:

   def class_factory
     return Class.new { @@x = 1 }
   end

   class_factory.class_eval { puts @@x } # 1

David

···

On Wed, 16 Mar 2005, Csaba Henk wrote:

On 2005-03-15, Lionel Thiry <lthiryidontwantspam@skynetnospam.be> wrote:

--
David A. Black
dblack@wobblini.net

Csaba Henk wrote:

Anyway, the short answer as far as I know is "no" :slight_smile:

Too bad! :slight_smile:

I do like having them. In fact, they are globals, wrapped in the
namespace of a class/module. There are situations when you need such a
beast, and it's better than an explicit global... and better than using a
container as a constant (just because constans don't like being
reassigned), that's really ugly.

There's still class instance variable.

class MyClass
  @a = "class instance value"

  attr_reader :a
  def initialize(value)
   @a = value
  end

  def a_of_the_class
   self.class.a
  end

  class << self
   attr_reader :a
  end
end

my_instance = MyClass.new("instance value")
puts my_instance.a # output: instance value
puts my_instance.a_of_the_class # output: class instance value

other_instance = MyClass.new("other instance value")
puts other_instance.a # output: other instance value
puts other_instance.a_of_the_class # output: class instance value

I prefer that way of doing things over the @@ way.

My problem is that you can't really access them from the outside, unless
accessor method are set up. By "from the outside" I mean that from code
which is not in the scope of a "class/module Foo ... end" thingy. Does
anyone know, eg, how to define a class variable in a nameless class?

With class instance variable, this is easier, I suppose, as you can write:
  class << self
   attr_reader :a
  end

···

On 2005-03-15, Lionel Thiry <lthiryidontwantspam@skynetnospam.be> wrote:

--
Lionel Thiry

let's go on... replace your last line with:

  (c = class_factory).class_eval { puts @@x }

and then:

  c.class_variables # =>
  @@x # => 1
  Object.class_variables # => ["@@x"]

What you suggest defines a class variable of Object, not of the nameless
class.

Csaba

···

On 2005-03-16, David A. Black <dblack@wobblini.net> wrote:

Do you mean like:

   def class_factory
     return Class.new { @@x = 1 }
   end

   class_factory.class_eval { puts @@x } # 1

There's still class instance variable.

class MyClass
  @a = "class instance value"

(snip)

I prefer that way of doing things over the @@ way.

Yes, you are right, you can in fact go that way. @@ is almost nothing
more than syntax sugar. But syntax sugar is an important component of
the rubyness of ruby...

When I write, "almost", I refer to the following slight difference:
within any subclass of the class defining @@x, it can be accessed
directly, without defining accessor methods and without a reference to
the scope where @@x was introduced. I can't give an example though where
this would have real importance... where you would use the subclass in a
way such that you don't really know in which class has the variable been
defined.

Anyway, if you look into (properly written) ruby code, and you see
@@foo, it sticks out, and you can guess its somewhat specific role in
that class design, and easily identify the way and the reason of its
usage. The same regards to constants, and it's a good thing IMHO.

With class instance variable, this is easier, I suppose, as you can write:
  class << self
   attr_reader :a
  end

Yes, I know. ATM it's a reason for preferring class instance variables
over class variables. But, what I mean doesn't contradict this. I
just said, it would be good if we had this easy accessors to class
variables as well.

Csaba

···

On 2005-03-16, Lionel Thiry <lthiryidontwantspam@skynetnospam.be> wrote:

Hi --

···

On Thu, 17 Mar 2005, Csaba Henk wrote:

On 2005-03-16, David A. Black <dblack@wobblini.net> wrote:

Do you mean like:

   def class_factory
     return Class.new { @@x = 1 }
   end

   class_factory.class_eval { puts @@x } # 1

let's go on... replace your last line with:

(c = class_factory).class_eval { puts @@x }

and then:

c.class_variables # =>
@@x # => 1
Object.class_variables # => ["@@x"]

What you suggest defines a class variable of Object, not of the nameless
class.

Ugh. Well, as I've said, I'd like @@var to disappear anyway :slight_smile:

David

--
David A. Black
dblack@wobblini.net

David A. Black wrote:

Hi --

Do you mean like:

   def class_factory
     return Class.new { @@x = 1 }
   end

   class_factory.class_eval { puts @@x } # 1

let's go on... replace your last line with:

(c = class_factory).class_eval { puts @@x }

and then:

c.class_variables # =>
@@x # => 1
Object.class_variables # => ["@@x"]

What you suggest defines a class variable of Object, not of the nameless
class.

Ugh. Well, as I've said, I'd like @@var to disappear anyway :slight_smile:

David

I agree!
I just don't understand all this code. (and with ruby 1.9.0, I feel even more confused with @@)

···

On Thu, 17 Mar 2005, Csaba Henk wrote:

On 2005-03-16, David A. Black <dblack@wobblini.net> wrote:

--
Lionel Thiry