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

Re: in defense of types




   Date: 29 May 2002 17:29:58 -0000
   To: matthias@cs.rice.edu
   From: Paul Graham <pg@archub.org>
   Subject: Re: in defense of types
   Cc: ll1-discuss@ai.mit.edu
   
   I admit that type declarations will help turn up bugs that 
   might not have been found till later, if at all.
   
   However, type declarations are only one of many assertions
   you might choose to make in the source of a program to
   catch bugs.  Why not let it be up to the programmer to
   decide which such assertions to make, and when?  What's
   special about variables' types that makes it a good idea to
   make assertions about them mandatory, at compile time?

It's very simple.  Names are the means by which relationships
are established between distant parts of a program text.
In particular, variables make it possible for a quantity
to be referred to many times in a program, whereas a quantity
that is merely the result of an expression is used only once,
locally, in the place where the expression is written.
It is the fact that a quantity may have connections to many
places in a program text that makes it valuable to document
the expected invariant properties of that quantity; type is
one useful kind of invariant.

This suggests further possible gradations in the Curl strategy;
for example, a compiler option that variables must have
types if they are referred to in more than N places, or if they
are referred to outside some limited region of the program text.

--Guy