From: Jake McArthur Date: 2006-05-16T03:37:05+09:00 Subject: Re: begining programmer questions --Apple-Mail-2--240175967 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On May 15, 2006, at 1:14 PM, Regg wrote: > But when I hear statements about Ruby being a strong type language, I > would expect that to be applied to variables. > > Most assignments happen between variables. Variables are not objects. They are simply names associated with objects. A name can be associated with any type of object. a = 1 b = a a = "foo" a # => "foo" b # => 1 What's special about the above? The returned 1 is the exact same object as the original literal when it was assigned to a! The object did not change type at all, only which objects the variables pointed to. > In C++ (a strong typed language) you can't do this: > > MyOtherClass *m_otherclass = new MyOtherClass(); > MyClass *m_class = new MyClass(); > > > m_class = m_otherclass; <--ERROR (Can't convert MyOtherClass to > MyClass) > > > but this seems to be possible in Ruby. I'm going to have to help you distinguish between strong typing and static typing.... C is a statically, weakly typed language. It is static because a variable can only be on a certain type, but it is weak because the data associated with that variable can be of any type. For example (untested and syntax may be bad): struct vector { double x, y, z; }; struct some24ByteStruct { int a, b; char c, d, e, f; double g, h; }; struct vector a = {2.0, 3.0, 4.0}; struct some24ByteStuct b = (struct some24ByteStruct)a; We know that we have some integers (b.a and b.b), some characters (b.c, b.d, b.e, and b.f), and some doubles (b.g and b.h), but this is scary stuff since we have no idea what kind of data will be in those variables. The former point is what makes C statically typed, but the latter point makes it weakly typed. Ruby is a dynamically, strongly typed language. It is dynamic because a variable can point to data of any type, but strong because that data will never change type. The Ruby example I gave above demonstrates this. Make any more sense now? - Jake McArthur --Apple-Mail-2--240175967--