Hi --

On Tue, 29 May 2007, Hakusa / gmail.com wrote:

> I remember reading that, in Python, working with variables can be slow
> because it needs to check if the variable is being changed to another
> type every time it's used. I don't know if Ruby is like that too, but
> this is for if it is.
>
> If they make it possible for explicit variable definitions. Let's say
> I've got an integer and there's no reason it would ever turn into a
> float or anything like that unless specifically noted. It might run
> faster because Ruby wouldn't have to mess with dynamic typing. And
> I've got a class that has a variable that is a string. I could
> immediately define it as a string the same way I would in C or Java.
> Ruby wouldn't have to check the type AND THEN initialize, it would
> already know the type!

s/type/class :-)  Type and class are not the same in Ruby.

> But I'm guessing that if this would be useful, it would have already
> been done. So am I right or can you tell me why I'm wrong?

If you tie variables themselves down to certain classes, you lose the
power of being able to address objects dynamically and without concern
for their class.  It would militate pretty directly against the kind
of "duck typed" programming Ruby is so suited for.


David

-- 
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
    (See what readers are saying!  http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)