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

From: Chris Uzdavinis (chris at atdesk.com)
Date: Wed May 30 13:59:49 EDT 2007

Matthias Felleisen <matthias at ccs.neu.edu> writes:

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

While I'm probably the biggest Scheme proponent in my company, I still
consider myself a C++ programmer first and foremost, and would like to
comment your characterization.  Though what you say is true, and it's
*possible* to do all sorts of evil things with your memory and objects
in C++, it's also entirely possible to make well-behaved, easy to
understand C++ code too.  That is, well-written C++ code not
misleading at all.  

Writing intentionally obscure, type-abusive code is not a trait of a
good C++ program.  Such coding does not have to appear anywhere in a
program at all, but it *can*.  Because it's possible to write bad
code, a lot of people conclude that C++ programmers simply like to do
that.  Ugly, unsafe code is a NOT a fundamental trait of a C++
program, and it doesn't have to be that way--and it's not that way in
our C++ code.

When you use different types for each unique idea in a program, then
you do get the benefit of documented intent, enforced by the compiler,
and it becomes a big debugging aid (as the compiler rigorously checks
your values and types match.)  Then just the operations on that type
manipulate the memory it represents, leaving the rest of the code to
simply make use of it.  Even if you find a situation where you do need
to do low level bit twiddling, it can be done in an isolated way
hidden behind an interface, hiding those details from clients that
need to use it.


Posted on the users mailing list.