From: dblack@... Date: 2006-05-15T14:33:16+09:00 Subject: Re: begining programmer questions Hi -- On Mon, 15 May 2006, Francis Cianfrocca wrote: > With some trepidation I'll commit the sin of threadjacking in order to > clarify some of this. I'm doing this because "weakly-typed" is an > unjustified criticism often made by Ruby's detractors, so I think it's > important for us to be able to answer it. > > A strongly-typed language has well-defined, unambiguous rules about the > operations that may be performed on an object, and it refuses to perform > inferred type conversions. (Which is why Ruby won't let you add numbers to > strings as Perl does.) Ruby doesn't ever figure out for itself what type an > object is. If you create an object yourself, you need to type it (generally > with Klassname.new, or one of the shorthands like x=[]). Of course, if you > call a method that returns an object, that object will have a type > (determined by the writer of the method) and you can use it without > declaring it, but that doesn't mean Ruby figured out the type on its own. It sounds like you're talking about class, rather than type. A string, for example (that is, an object that says "String" when you ask it its class), can allow integers to be added to it, and is therefore of class String but of *type* "string-like thing that lets you add integers to it" (or whatever). So the type of Ruby objects is almost a tautology: the type of object o is "the type of objects that have the capabilities and interface of object o." Class, meanwhile, though more tangible in a sense, is only the starting point for the object's life-cycle. David -- David A. Black (dblack@wobblini.net) * Ruby Power and Light, LLC (http://www.rubypowerandlight.com) > Ruby and Rails consultancy and training * Author of "Ruby for Rails" from Manning Publications! > http://www.manning.com/black