Python from Wise Guy's Viewpoint

Fergus Henderson fjh at cs.mu.oz.au
Mon Oct 27 12:50:24 EST 2003


"Paul F. Dietz" <dietz at dls.net> writes:

>Ralph Becket wrote:
>
>> Here's the way I see it:
...
>> (3) type errors flagged by a compiler for an ESCTS can pinpoint the source
>>   of the problem whereas ad hoc assertions in code will only identify a
>>   symptom of a type error;
...
>BTW, is (3) really justified?  My (admittedly old) experience with ML
>was that type errors can be rather hard to track back to their sources.

It depends on whether you declare the types of functions or not.
If you leave it up to the compiler to infer the types of all the
functions, then compilers have a difficult job of pinpointing errors,
because sometimes your incorrectly-implemented functions will be
type-correct, just with a different type than you expected, and this
will then leave to type errors further up the call tree.

But declaring the intended types of functions improves things dramatically.
If you get a type error, and you can't immediately figure out what is wrong,
declaring the intended types of the functions involved and recompiling
will allow you to quickly pinpoint the problem.

Of course, the type checker's error messages won't tell you _exactly_
where the error is; they can only point out inconsistencies, e.g. between
the code for a function and its type declaration, or between the code
for a function and one or more of the type declarations for the functions
that it calls.  But such inconsistencies should be easy to resolve;
the programmer should be able to tell which of the contradictory parts
are wrong.  (The exception is when the inconsistency actually reveals
a design error; in the worst case, a major redesign may be required.)

-- 
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