Comparison between C++ and Ruby Variables

M

Mayank K.

I have blogged about the comparison between c++ and ruby variables and
it would great if people can comment on it if something should be
changed or I am missing some concept. Accordingly I can update the blog
as I want it to be correct, so that people are not misled by some wrong
information.

Thanks,
Mayank Kohaley
 
P

Phillip Gawlowski

I have blogged about the comparison between c++ and ruby variables and
it would great if people can comment on it if something should be
changed or I am missing some concept.

A link to your blog post would help with that, I bet. ;)


--
Phillip Gawlowski

Though the folk I have met,
(Ah, how soon!) they forget
When I've moved on to some other place,
There may be one or two,
When I've played and passed through,
Who'll remember my song or my face.
 
M

Mayank Kohaley

[Note: parts of this message were removed to make it a legal post.]

On Wed, Mar 9, 2011 at 6:25 PM, Phillip Gawlowski <
A link to your blog post would help with that, I bet. ;)


--
Phillip Gawlowski

Though the folk I have met,
(Ah, how soon!) they forget
When I've moved on to some other place,
There may be one or two,
When I've played and passed through,
Who'll remember my song or my face.
Sorry guys totally missed it .Herr it is: http://mayankkohaley.blogspot.com/
 
M

Mayank Kohaley

[Note: parts of this message were removed to make it a legal post.]
You write "The Class variable in Ruby is similar to static member variable
of C++." This is not true.


Can you please explain how exactly it is different from static member
variables of C++.
 
M

Mayank Kohaley

[Note: parts of this message were removed to make it a legal post.]
You write "The Class variable in Ruby is similar to static member variable
of C++." This is not true.


Can you please explain how exactly it is different from static member
variables of C++.
 
M

Mayank Kohaley

[Note: parts of this message were removed to make it a legal post.]
You write "The Class variable in Ruby is similar to static member variable
of C++." This is not true.


Can you please explain how exactly it is different from static member
variables of C++.
 
R

Robert Klemme

Can you please explain how exactly it is different from static member
variables of C++.

I am sorry, there is a ton of material on class variables and their
oddities online (even in the archives of this forum). Please look it
up.

Basically you cannot do that with static member variables in C++:

16:23:10 Temp$ ruby19 cv.rb
B1
2
S1
2
B2
1
S2
1
16:23:13 Temp$ cat -n cv.rb
1 class B1
2 @@foo =3D 1
3 def self.show; p @@foo; end
4 end
5 class S1 < B1
6 @@foo =3D 2
7 def self.show; p @@foo; end
8 end
9 class B2
10 end
11 class S2 < B2
12 @@foo =3D 2
13 def self.show; p @@foo; end
14 end
15 class B2
16 @@foo =3D 1
17 def self.show; p @@foo; end
18 end
19 [B1,S1,B2,S2].each do |cl|
20 puts cl
21 cl.show
22 end
16:23:16 Temp$

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
K

Kirk Haines

com/

You write "The Class variable in Ruby is similar to static member variabl=
e of C++." =A0This is not true. =A0You also do not mention the particular p=
eculiarities that pop up when mixing class variables with inheritance and i=
nitialization order. =A0For a rough equivalent for static members in C++ I =
would rather choose class instance variables.
Personally I would either not mention class variables, mention them and s=
ay "don't use them" or mention them, explain them and say "don't use them".

Yeah. I'd concur. Explain them, but go into details as to why they are
generally not a good idea, and why class instance variables are
generally a much better choice.

I'd also explain that class instance variables are _really_ just
instance variables. They aren't a special case.


Kirk Haines
Software Engineer
EngineYard
 
M

Mayank Kohaley

[Note: parts of this message were removed to make it a legal post.]

variable of C++." This is not true. You also do not mention the particular
peculiarities that pop up when mixing class variables with inheritance and
initialization order. For a rough equivalent for static members in C++ I
would rather choose class instance variables.
say "don't use them" or mention them, explain them and say "don't use them".

Yeah. I'd concur. Explain them, but go into details as to why they are
generally not a good idea, and why class instance variables are
generally a much better choice.

I'd also explain that class instance variables are _really_ just
instance variables. They aren't a special case.


Kirk Haines
Software Engineer
EngineYard
Thanks a lot guys for inputs I have changed the blog post accordingly with a
word of caution about the class variables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top