[plt-scheme] Why do folks implement statically typed languages?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed May 30 12:57:29 EDT 2007

This is an interesting analysis, but I'd like to suggest alternative  
thoughts:

On May 30, 2007, at 11:37 AM, hendrik at topoi.pooq.com wrote:

1.

> When Lisp was new, they just didn't know any better.

I think this is incorrect. John McCarthy was a member of the Algol 60  
club and was well-aware of types. Algol 60 is a type-sound kernel  
language. I urge you to read John Reynolds's papers on the essence of  
Algol.

2.

> Dynamically typed languages also tend to be easier to implement,

badly and inefficiently.

That's what you should have added. The type annotation in a program  
in a SL give the compiler a lot of knowledge. The most important  
advantage is that the compiler can determine the memory layout from  
these annotations and exploit this layout information for access.  
Just think of an array of numbers in Java vs a vector of numbers in  
Scheme. On the average, you need two memory accesses for the latter  
while you can get away with one for the former. If your compiler is  
smart and well-written, you can often avoid one in Scheme .. but you  
need LOTS of smarts in the implementation.

A slogan to remember this by: typed languages make programmers work  
for the compiler.


3.

> And, just to make it clear, C and C++ appear to have static typing,  
> but
> it doesn't accomplish the task it ought to, so the effort expended on
> it is somewhat wasted.

Amen. This is what I alluded to in my message using the phrase  
"unsound." What this means concretely is that

  int x

in a C++ program is completely totally misleading. Depending on your  
program, the bits in x may come from a string, a function, combine a  
bunch of booleans, or what-have-you. It doesn't serve as  
documentation for maintenance and it certainly doesn't serve as clue  
during debugging.

4.

> But, speaking as a programmer that has to ensure that my systems work
> correctly, I far prefer to use secure languages that perform their  
> type
> checking statically.

This is the standard SL ideology but there is little software  
measurement work that backs it up.

I have logged all errors for a year, when I was programming SML/NJ  
and Chez Scheme. I have looked at errors in our bug database. Yes,  
there is the occasional bug that slips through unit testing and could  
have been caught by a type system more quickly. BUT, since one needs  
unit testing anyway, this is almost a non-issue. Most bugs in our  
world are deep logical bugs, not amenable to type checking.

The one advantage re program development I will grant -- without  
caveat -- is that a sound explicit type system provides valuable  
clues to maintainers and testers and debuggers. Which is why I am  
pushing Typed Scheme.

-- Matthias




Posted on the users mailing list.