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.
A link to your blog post would help with that, I bet.
···
On Wed, Mar 9, 2011 at 1:12 PM, Mayank K. <mayank.kohaley@gmail.com> wrote:
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.
--
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.
On Wed, Mar 9, 2011 at 6:25 PM, Phillip Gawlowski < cmdjackryan@googlemail.com> wrote:
On Wed, Mar 9, 2011 at 1:12 PM, Mayank K. <mayank.kohaley@gmail.com> > wrote:
> 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.
You write "The Class variable in Ruby is similar to static member 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.
Personally I would either not mention class variables, mention them and say "don't use them" or mention them, explain them and say "don't use them".
Oh, and then there are nice things as static variables in methods in C++ as well...
Kind regards
robert
···
On Wednesday, March 9, 2011 3:05:13 PM UTC+1, Mayank Kohaley wrote:
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
···
On Wed, Mar 9, 2011 at 7:25 AM, Robert Klemme <shortcutter@googlemail.com> wrote:
On Wednesday, March 9, 2011 3:05:13 PM UTC+1, Mayank Kohaley wrote:
You write "The Class variable in Ruby is similar to static member 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.
Personally I would either not mention class variables, mention them and say "don't use them" or mention them, explain them and say "don't use them".
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 = 1
3 def self.show; p @@foo; end
4 end
5 class S1 < B1
6 @@foo = 2
7 def self.show; p @@foo; end
8 end
9 class B2
10 end
11 class S2 < B2
12 @@foo = 2
13 def self.show; p @@foo; end
14 end
15 class B2
16 @@foo = 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
···
On Wed, Mar 9, 2011 at 3:56 PM, Mayank Kohaley <mayank.kohaley@gmail.com> wrote:
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++.
Thanks a lot guys for inputs I have changed the blog post accordingly with a
word of caution about the class variables.
···
On Wed, Mar 9, 2011 at 8:57 PM, Kirk Haines <wyhaines@gmail.com> wrote:
On Wed, Mar 9, 2011 at 7:25 AM, Robert Klemme > <shortcutter@googlemail.com> wrote:
> On Wednesday, March 9, 2011 3:05:13 PM UTC+1, Mayank Kohaley wrote:
>> Sorry guys totally missed it .Herr it is: http://mayankkohaley.blogspot.com/
>
> You write "The Class variable in Ruby is similar to static member
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.
>
> Personally I would either not mention class variables, mention them and
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.