From: Elliot Temple Date: 2006-05-16T05:51:10+09:00 Subject: Re: begining programmer questions On May 15, 2006, at 1:27 PM, Regg wrote: > " MyClass * m_class = (MyClass) m_otherclass; > m_class->do_something(); > > Obviously the hammer cast breaks the type safety, and produces > similar > undefined behavior. It all about having the wrong data in the > m_class > pointer variable. In one case it's a null pointer, in the other case > it's an inappropriate pointer. I would call them both type errors." > > This is something that YOU are forcing the compiler to do. > You are FORCING the compiler to accept this assignment even if it's > wrong. > That is not the fault of the language but the fault of the developer. > > But in Ruby you are not forcing it, it just allows it to happen > with no > warning. In ruby it does not happen at all. when you bind foo = 5, that is fine. when it's bound to "hi" that is fine as well. there are no objects that foo shouldn't be bound too. there is no cast happening when you do foo = "hi" foo = 5 foo just points to something new, now, and the "hi" gets lost in the abyss (unless something else is pointing to it) the C code above treated some bits representing one thing as if they were representing something else. ruby doesn't do that just by assignment. when you do foo = 5 ruby now treats foo like an integer not a string. if you want 5 treated like a string you have to convert it. -- Elliot Temple http://www.curi.us/blog/