On Mon, Nov 15, 2010 at 8:57 AM, Mike Stephens <rubfor / recitel.net> wrote:
> Robert Klemme wrote in post #961079:
>> Duck typing really only means that Ruby does not have interfaces and >uses
> dynamic typing.
>
> OK so what's the difference between dynamic typing and weak typing?

Dynamic typing only says something about _when_ types are evaluated.
In dynamically typed languages variables typically do not have a type
and typing is enforced at runtime.

Weak typing OTOH is about _what_ you can do with "something".  In C
you can easily cast a char* to a int* and use it as that (e.g. for
math).  That's weak typing.  Such things are impossible in a strongly
typed language - either dynamic or static typed.

> My take on strong typing is you cannot assign an object of Type A to a
> variable of Type B unless you use a transform method so you convince the
> 'compiler' you intended to do this (and such a method exists).

You describe a language with strong typing *and* static typing.  In a
language which does not have static typing the statement you make is
meaningless because variables do not have a type there (as in Ruby).

> It's more
> to do with trapping programmer errors than to do with making compilers'
> lives easy.

That is a description of a goal but not of a technology.

> Where that leaves you on adding (etc) an object of Type A to
> an object of Type B is less clear but I would be inclined to think that
> falls into the same camp.

The mere fact that you can add a string and an integer does not tell
you much about the nature of the type system.  In Ruby you have
#coerce and in C++ you have operator overloading.  Both languages are
statically typed.  If you define an operator like in the C++ program
below you still have static and strong typing (at least for this piece
of code, you can still cast via void* in C++) even though you can add
strings and integers.

Kind regards

robert


#include <string>

int operator + (const std::string& s, const int i) {
  return i + s.length();
}


int main(int argc, char* argv[]) {
  std::string x(argv[0]);
  return x + argc;
}

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/