From: Logan Capaldo Date: 2006-05-16T06:21:46+09:00 Subject: Re: begining programmer questions On May 15, 2006, at 3:04 PM, Regg wrote: > In your example: > > " struct vector a = {2.0, 3.0, 4.0}; > struct some24ByteStuct b = (struct some24ByteStruct)a;" > > You are manually forcing this relationship my casting one type to > another. > > To me that is one of the things I love about C is that it will > allow you > do something that the compiler otherwise would not allow. > > But in Ruby you are not "forcing" the type casting, it just does it > without any warning or error. > > So I still can't see how it can be said that "Ruby is a dynamically, > strongly typed language". > > It seems to be a dynamically, "any" typed language. > > What benefit is gained from a variable being (switched/pointed to) > from > one type to another? (This is an honest question, maybe I'm missing > something) > > It seems like a recipe for disaster. > > Thanks I like to explain the differences like this: 1) With static, strong typing the variables are typed 2) With weak typing the operations are typed 3) With dynamic, strong typing the objects are typed. So with 1) we have C++ string a = 7; compile time error 2) we have perl $a = 1 + 7; $b = 1 . 7; $a is 8, $b is "17". 3) We have ruby and python and smalltalk and some others a = 7 b = "string" c = a + b Runtime error, you can't add a string to a number The (4) one which I didn't mention was static weak-typing which is C. You're right that you have to explicitly cast the type, but the problem is unless it's one of those "magic" casts like from double to int what you are _literally_ doing is changing the type (w/o changing the representation). In C I can actually write this: double q = 2.0; printf("%s\n", (char *)q); (char *)q does not make me a string "2.0", it just says take this memory address and treat it as a pointer to a char. This will hopefully segfault, but maybe it won't and it will print something very odd. You can see the weak-typing I hope. Of course the upside is is that it is exactly this capability that lets us have our Fixnums, nil, true, false, and Symbols as immediate values.