Dan Doel
11/12/2003 6:00:00 PM
Hi,
Duck typing is essentially dynamic typing.
The main ethos for a large number of Ruby programmers (note that there
are also those that are
into static typing), is that you don't worry about types. In Ruby an
object's class is not its type,
unless you're talking singleton class, in which case each object has its
own type (which isn't useful).
So, rather than worrying about type, you just worry about the behavior
shown by the objects.
Note that this doesn't mean you check for all the appropriate methods
and all that. Then you're
going back to static typing. Just document that certain functions
require arguments to respond
to certain methods, and only call those methods with appropriate
arguments. And feel free to
unit test a lot to make sure everything responds as asked.
Basically, it's design by contract without contracts being enforced with
code.
Hope this helps.
- Dan