[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cheerful static typing (was: Any and Every... (was: Eval))




How about this: There are three kinds of errors: 

 1. syntax errors
 2. run-time errors concerning the abuse of a primitive 
 3. logical errors. 

Catching something at level 1 often, but not always prevents something of
level 2. Ditto for levels 2 and 3. 

The first category includes things such as 
 x = 1 + ; x
and 
 x + "true" 
in a statically typed language. Who specifies this? The grammar and typing
rules. Aka, syntax. 

The second kind of error is an abuse of a language primitive (not a lib
function that (could be) defined in terms of the language proper) even 
though the correct 'type' of argument flows into the primitive: 
 (/ 1 0)
and 
 (first empty)
come to mind. Who specifies these potential errors? The
semantics. The semantics of a language guarantees the coherence of data
manipulation. Nothing more, nothing less. The contract between the language
designer and the language user is all about which primitive program
operations raise exceptions. So yes, contracts must talk about exceptions. 
 
The third kind of error is an error in the logic of the program. If someone
has an independent specification of what the program is supposed to do
(perhaps because some other implementation exists and is called "canonical"
for some spelling of the word) and the two disagree then the program's
logically wrong. What's wrong with having an independent spec that says in
some cases an exception is raised? 

A last parting thought. When you have have contracts, specify who is
obligated to do what (often implied) and make sure that the contract is
monitored so that the "guilty party" is blamed. That's something where we
have failed to do a good job moving from 1/2 to 3. 

-- Matthias