In article <3C14DD65.4090602 / vt.edu>, Roy Patrick Tan  <rtan / vt.edu> wrote:
>I have just recently read an old paper by Wirth "On the Design of
>Programming Languages", which started me thinking about dynamic typing.
>
>One of the lessons he enumerated:
>
>"Design languages such that most checking operations can be performed at
>compile time, and need not be deferred until execution. The concept of
>static data types of variables is essential in this respect, and enhance
>both programming security and system efficiency."
>
>Hoare also has similar comments about static typing.

Sure, Wirth is a great language designer, but this is his opinion.

>
>Now, given that ruby is interpreted, much of the efficiency and type 
>safety aspect might not matter (though, if/when it gets bytecode 
>compiled, I can see that static typing can improve both).
>
>However, it seems that dynamic types can be more error prone and harder
>to read, since we can't be sure what type of object a variable holds. I
>guess what I'm asking is: given the advantages of a statically typed
>language, does dynamic typing offer any benefits? What is the reason
>behind ruby's dynamically typed variables?
>

First off, In Ruby and other dynamic languages the type checking is done 
by determining (at run-time, true) whether an object can respond to a 
certain message sent to it - if it can't then an exception is raised.

In a static OO language (Java, C++) variables have to hold objects of a 
certain type (which tends to lead to all kinds of casting which sort of 
negates the advantages of compile-time type checking).  In a dynamic OO 
language like Ruby or Smalltalk all that is required is that an object 
respond to a certain method.

I'm finding that the dynamically typed languages are quite freeing.  If I 
have a system where I pass around objects to other objects and the 
receiving objects then call a certain method on the received object (say 
'run' for what I'll call a Runnable object) then if I, or a user of these 
classes decide that they want a different kind of runnable object that 
performs a differnt function when 'run' is called, all they 
have to do is define another class of their own and make sure it's objects 
respond to 'run'.  This is what is known as generic programming - 
doing generic programming in languages like C++ requires a lot of mucking 
about with templates (and in Java, since they don't have templates I 
suppose they do it with lots of casting) and the C++ programmers make a 
big deal about how to do something which is quite trivial in languages 
like Ruby.

Phil