Python from Wise Guy's Viewpoint

Pascal Costanza costanza at web.de
Mon Oct 27 09:20:06 EST 2003


Ed Avis wrote:
> Pascal Costanza <costanza at web.de> writes:
> 
> 
>>>Should we then conclude that compile-time syntax checking is not
>>>worth having?
>>
>>No. Syntax errors make the program fail, regardless whether this is
>>checked at compile-time or at runtime.
>>
>>A type "error" detected at compile-time doesn't imply that the
>>program will fail.
> 
> Actually it does, in a statically typed language.

No, it doesn't.

> If you write a
> function which expects a Boolean and you pass it a string instead,
> it's going to fail one way or another.

Yes, that's one example. This doesn't mean that this implication always 
holds. What part of "doesn't imply" is the one you don't understand?

> OK, the bad call of that function might never be reachable in actual
> execution, but equally the syntax error in Tcl code might not be
> reached.  I'd rather find out about both kinds of mistake sooner
> rather than later.

I don't care for unreachable code in this specific context. A part of 
the program that passes a value of type "don't know" to a variable of 
type "don't know" might be unacceptable to a static type sytem, but 
might still not throw any exceptions at all at runtime. Or, in other 
scenarios, only exceptions that you can correct at runtime, which might 
be still useful, or even the preferred behavior.

> (I do mean a type error and not a type 'error' - obviously if you have
> some mechanism to catch exceptions caused by passing the wrong type,
> you wouldn't want this to be checked at compile time.)

Exactly.


Pascal

-- 
Pascal Costanza               University of Bonn
mailto:costanza at web.de        Institute of Computer Science III
http://www.pascalcostanza.de  Römerstr. 164, D-53117 Bonn (Germany)





More information about the Python-list mailing list