Who's minister of propaganda this week?

Michael Chermside mcherm_python at yahoo.com
Thu Mar 15 02:14:21 CET 2001

Alex Martelli wrote:
         ... [snip]...

  > So, all the compile-time checking is buying is catching (a small
  > subset of) the errors that would be caught in testing anyway, a
  > little bit earlier (thus, a little bit cheaper) -- it's never the
  > case that one has to write a test which would not be needed at
  > all if type-checking was static, since "the object has the right
  > type" is a small subcase of "the object _behaves_ per the specs".
I'm really not sure I see it this way. If the method  foo(x) is known to
take a FancyDateObject
there are three kinds of errors we could make. One is that foo() is
written badly so it
doesn't do what it's supposed to. The unit tests of foo() need to guard
against this.
Another possible error is that FancyDateObject isn't written properly.
The unit tests
of FancyDateObject need to guard against this. And the third type of
error is that
that somewhere where we CALL foo(), we might pass it a DateObject
instead... or
even a String... which will cause it to perform wrong. To guard against
this in a
dynamically typed language, we have to write unit tests for *every
single place*
that we call foo(). Of course, we'd be writing unit tests for those
functions anyway,
but we won't be able to assume that foo() works properly, and will need
tests to ensure this.

In a staticly typed language, we still need the unit tests for cases 1
and 3, but the
third type of error is caught by the compiler. And in my mind, ANY TIME that
I can have a machine do my work for me it's better... I can be lazy, and
the machine
never gets tired after a long day and forgets to test sometimes. Of
course, I can
put an assert at the top of foo() which asserts that x is of type
but if I always assert the types of my arguments then I'm basically
using a staticly
typed language.

There are times when a dynamically typed language is more flexible, and
it's certainly
nice not to have to declare everything just to specify its type, but
there ARE
advantages to static typing, and this, I believe, is the biggest one.

-- Michael Chermside

Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

More information about the Python-list mailing list