Why static typed languages are sometimes better.

Mike Austin mike at mike-austin.com
Fri Jul 2 08:29:40 CEST 2004

"Roy Smith" <roy at panix.com> wrote in message
news:roy-C894A6.17435601072004 at reader2.panix.com...
> I just had an interesting little surprise.  I've got a method that takes
> a string as an argument.  I wanted to change it to take either a string
> or a tuple of strings, so I did my usual "test first" thing.
> I changed the unit test I already had from calling it with a string to
> calling it with tuple of two strings.  I then ran the test, expecting it
> to fail.  The next step would be to go write the code to make the test
> pass.
> Amazingly, the test passed (that means I'm done, right?).  Well, it took
> me a moment to realize that the only thing I ever do with the argument
> in the current version is use it as a dictionary key.  Since a tuple of
> two strings is a valid key, so the test passed just fine.  Sometimes the
> language is just too forgiving :-)

There are dynamically typed language such as Dylan and CLOS that can put
restrictions on what type of arguments are passed to functions, and fail if
there is no match.  Although this is using a mechanism -- multimethods.  On
that thought, are multimethods considered to be a form of type checking, or
simply a mechanism? Hmm.

Mike Austin

More information about the Python-list mailing list