[M3devel] static typing [WAS: JIT, WAS: Google Benchmark - anyone interested in an Modula 3 version?]

Rodney M. Bates rodney_bates at lcwb.coop
Sun Jul 10 15:32:52 CEST 2011


On 07/05/2011 09:06 AM, Hendrik Boom wrote:
 > If understand correctly, these results are about figuring out what types
 > the programmer meant if he failed to specify any.  My view is that the
 > programmer probably knew full well what he meant, and he might as well
 > say so, in the interest of clarity if nothing else.  I find programs
 > with secret types to be incomprehensible, even while I'm writing them.
 >
 > And getting error messages if what I wrote doesn't match what I
 > intended, and getting better run-time, well, those are wonderful
 > consequences.
 >
 > -- hendrik
 >

Yes, well said!

Here is a section of a draft of an article I have been working on, regarding
why I think systematic dynamic typing in programming languages is, for everyday
programming, a really bad idea.  It's just one of several arguments.

------------------------------------------------------------------------

1) Dynamic typing is seldom either needed or used.

The majority of variables (1) in sensible programs are what I call
_algorithmically statically typed_.  By this, I mean, informally, that
there is a natural type for the variable that can be inferred from its
assignments and uses.  Moreover, this is a static property, i.e.,
independent of the program's inputs, and thus can be inferred from the
code alone.

Slightly more formally, it means that either assignments or uses of
values that are not members of this type represent buggy behavior, or
at best are pathological coding and irrelevant to correct behavior.
In practice, this almost always means such assignments don't belong,
and such uses will result in immediate crashes.

There are a lot of pathological cases that would belie my claim, but
very few that represent either correct and useful program behavior or
sensible coding style.  For more elaborate discussion of some such
cases and even where they might occasionally be useful, see (I).

This concept applies to object-oriented programming.  The algorithmic
static type of a variable is just a common supertype of the types the
variable could take on.  This needs to be high enough in the class
hierarchy to encompass all the useful values, but not so high that it
includes anything lacking a method that could be invoked on the
variable.  Rarely will this be the most-general type in the language.

In a statically typed language, the programmer will declare the
variable with a type equal to its algorithmic static type.  I call
this the variable's _linguistic static type_.  Otherwise, a compile
error will almost always result.  In a dynamically typed language,
nothing in the code gives the type explicitly, yet it is nevertheless
a static property that is vital to a reader's understanding.  Often,
it will be hard work for a reader to infer.

------------------------------------------------------------------------

Rodney Bates



More information about the M3devel mailing list