Test cases and static typing

Fergus Henderson fjh at cs.mu.oz.au
Wed Oct 29 02:40:02 EST 2003


Pascal Costanza <costanza at web.de> writes:
>Fergus Henderson wrote:
>> Pascal Costanza <costanza at web.de> writes:
>>>What I want is:
>>>
>>>testxyz obj = (concretemethod obj == 42)
>>>
>>>Does the code compile as long as concretemethod doesn't exist?
>> 
>> No, because the likelihood of that being a typo (e.g. for `concrete_method')
>> is too high.
>
>This proves that a static type system requires you to write more code 
>than strictly necessary.

True in the sense that "there exists a static type system that requires ...".
That is true for several static type systems that I know --
but the amount of extra code required is very very small.
E.g. in Haskell it is usually sufficient to just write

	concretemethod = error "stub"

However, your statement would be false if you tried to generalize it to
all languages and language implementations that have static type systems.
As I said, it would be easy to modify a statically typed system to
optionally allow references to undefined functions, and indeed there
are some systems which do that.  (For example I think ObjectCenter,
and interpretive environment for C/C++ programs, did that.)

If a couple of potential users of Mercury were to ask for it, I would
go ahead and add support for this to the Mercury implementation.  But
so far, to the best of my knowledge, no Mercury user has ever asked for it.

>> It would be fairly straight-forward to also add support for allowing
>> code like that to compile even if there was no declaration, but that
>> does not seems like a good idea to me - it would make it easier for
>> typos to go unnoticed, with insufficient compensating benefit.
>
>A good development environment gives you immediate feedback on such 
>kinds of typos. A good compiler for a dynamically type language issues a 
>warning. So these typos don't go unnoticed.

My experience is that compiler warnings are too easily ignored.

As for error highlighting in IDEs, well... Firstly, as you yourself
mentioned, not everyone wants to use a complicated IDE.

Secondly, even in such an IDE, I think errors could still slip through
unnoticed.  For example, consider the following scenario.  You might
write a call to a new function, which will get highlighted.  But you
expect that, since the function is not yet defined so you ignore the
highlighting.  Then you write another call to the function, which also
gets highlighted, and again you ignore it, since you expected that.
Finally you write the definition of the function, and run the program.
The compiler reports a few dozen warnings, which you ignore, since they
all seem to be referring to some undefined stubs in part of the program
that one of your colleagues is responsible for.  Then you run a few tests,
which all work, so you check your change in to the shared repository and
go home for the weekend.

Your colleague, who is working all weekend to get things ready for an
important demo, does a cvs update and incorporates your change. But when
he runs _his_ test case, it now crashes with an error about
"undefined function 'tingamajig_handler'"!  He greps the source
for "tingamajig", but the only occurrence is the one single place
where it is called, which happens to have absolutely no comments about
what it is supposed to do.  In desparation, he tries calling you,
but your mobile phone's battery has run flat.  He tries to implement
"tingamajig_handler" himself, but has no idea of what invariants it
is supposed to enforce, and eventually gives up.  The demo on Monday
morning is a complete failure.

On Monday afternoon, he finally catches up with you, and tells you of his
woes.  You see immediately that the problem was just a simple typo --
the function was named "thingamajig_handler", not "tingamajig_handler".


A far-fetched hypothetical?  Possibly.  But if you tell us that
"typos don't go unnoticed", please forgive me if I am a little skeptical ;-)

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.




More information about the Python-list mailing list