Newsgroups: comp.lang.misc
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!pa.dec.com!jrdzzz.jrd.dec.com!tkou02.enet.dec.com!jit533!diamond
From: diamond@jit533.swstokyo.dec.com (Norman Diamond)
Subject: Re: Run-time Type Errors in Smalltalk
Message-ID: <1991May13.082152.29294@tkou02.enet.dec.com>
Sender: usenet@tkou02.enet.dec.com (USENET News System)
Reply-To: diamond@jit533.enet@tkou02.enet.dec.com (Norman Diamond)
Organization: Digital Equipment Corporation Japan , Tokyo
References: <2604@calmasd.Prime.COM> <ROCKWELL.91May2222805@socrates.umd.edu> <1991May9.023313.28308@tkou02.enet.dec.com> <1991May13.061520.11992@daffy.cs.wisc.edu>
Date: Mon, 13 May 1991 08:21:52 GMT
Lines: 75

In article <1991May13.061520.11992@daffy.cs.wisc.edu> quale@khan.cs.wisc.edu (Douglas E. Quale) writes:
>In article <1991May9.023313.28308@tkou02.enet.dec.com> diamond@jit533.enet@tkou02.enet.dec.com (Norman Diamond) writes:
>>When mismatches are detected (which can benefit greatly from mechanical
>>assistance or compilers), they can be inspected manually to see if they are
>>really errors, or which part has the errors.  This is far better than skipping
>>half of them and letting 10% or 90% of the other half remain undetected.
>
>This statement suggests that programs compiled in dynamic languages contain
>more type errors than similar programs written in statically typed languages.

Try:  a smaller percentage of the type errors are caught.
To prove this would require translation from an untyped language to a typed
language, taking care to assign correct types but without correcting errors
that are caught at that stage -- then seeing what a compiler would catch.
I also don't know anyone who has done this kind of arcane study.

In general, some studies have shown that the ratio of bugs remaining in a
program (to the size of the program) tends to be proportional to the ratio
of bugs that have been caught and removed.  This relationship is not an
inverse one.  Of course, if the product lives long enough and newly caught
bugs decline in frequency, then one might expect remaining uncaught bugs
to have declined similarly.

I suggested as a rough approximation that each KIND of error shows similar
behavior, except when the compiler prevents certain kinds of errors.

>In considering the evidence presented by both
>sides I show my bias by giving greater weight to those who have actually
>used dynamically typed languages.

In chronological order, APL, Snobol, Unix shell and other command languages,
and Smalltalk.

>Dynamic typing makes program components easier to test interactively in
>isolation; the components get tested again together.  You may say you do
>all these tests in your statically typed language even though it's very
>inconvenient.

I didn't see it as inconvenient.  Now, some people see testing as
inconvenient, but I haven't heard typing asserted as the reason.

>I ask you, does everyone?

This is really an irrelevant question.  It is possible to code untested
programs in every language.  There will never be a language in which it
is impossible to write untested programs.

If a developer WANTS to be incompetent, maybe static vs. dynamic doesn't
matter -- well, maybe it does ... if a programmer wants to be incompetent
and lazy, then dynamic has its advantages.  (PLEASE NOTE:  this is not
intended as a slur against dynamic typing, or against valid arguments
for dynamic typing.  In fact, I also need dynamic typing on occasion.)

>Static type systems can actually be MUCH LESS SAFE than dynamic type systems.

Static typing is not less safe than dynamic typing.  Escapes from static
typing can certainly be unsafe, and incompetent escapes most likely are.

>A specific example is provided by the X Toolkit Intrisics.
>To get information from a widget you use a call that looks like this:
>  XtVaGetValues(widget, XtNwidth, &width, XtNheight, &height, NULL);
>Unfortunately width and height are type XtArgVal which is a union which
>completely defeats any typechecking.  The correct type is Dimension, should
>I instead use int I get no help from the compiler, and my code has a type
>error.  This kind of type error CANNOT occur in a dynamically typed
>language.

It could occur in a dynamically typed language, if the programmer can tell
the language to throw away tagging and type-checking.  A competent programmer
would put a tag in the union type.  (C is not an encouraging language for
this kind of practice, but it still could be done.)
--
Norman Diamond       diamond@tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
Permission is granted to feel this signature, but not to look at it.
