[comp.object] Static typing: the OOP seatbelt

chip@tct.uucp (Chip Salzenberg) (03/28/91)

According to rick@cua.cary.ibm.com.UUCP (Rick DeNatale):
>I'm actually a little bit surprised that people put so much faith in compile
>time type checking systems that they are willing to accept an implementation
>that allows type errors that escape the compiler to cause wild branches and
>other unsavory acts ...

Please note!  The C++ type system does, in fact, prevent such type
errors -- UNLESS the programmer lies to the compiler about the type of
an object.  Such lies are entirely the programmers fault, and do not
reflect badly on the language.

>I haven't seen a strong typing system yet that doesn't require you to 
>(hopefully carefully) circumvent it at times ...

And I, in turn, have never seen an automobile in which it is not
necessary to take off the seatbelt occasionally, even when driving.
That doesn't mean that seatbelts are counterproductive.

We've all heard the stories of people who drowned in their submerged
cars because they couldn't unfasten their seatbelts.  But such
anecdotes leave unmentioned the thousands of lives that are lost in
mundane accidents, lives that could have been saved if only seatbelts
were used.  Arguments against static typing are often based on similar
anecdotal evidence; such arguments are similarly bogus.
-- 
Chip Salzenberg at Teltronics/TCT     <chip@tct.uucp>, <uunet!pdn!tct!chip>
   "All this is conjecture of course, since I *only* post in the nude.
    Nothing comes between me and my t.b.  Nothing."   -- Bill Coderre

carroll@cis.udel.edu (Mark Carroll) (03/29/91)

In article <27F11D7B.6309@tct.uucp> chip@tct.uucp (Chip Salzenberg) writes:
>According to rick@cua.cary.ibm.com.UUCP (Rick DeNatale):
>>I'm actually a little bit surprised that people put so much faith in compile
>>time type checking systems that they are willing to accept an implementation
>>that allows type errors that escape the compiler to cause wild branches and
>>other unsavory acts ...
>
>Please note!  The C++ type system does, in fact, prevent such type
>errors -- UNLESS the programmer lies to the compiler about the type of
>an object.  Such lies are entirely the programmers fault, and do not
>reflect badly on the language.
>

But C++ has it's share of semantic ugliness. Consider the (now) well
known problems of copy constructors. Or the fact that it requires you
to use multiple inheritance in order to kludge a simulation of dynamic
typing. (Sorry, I'm one of the folks who still don't believe in multiple
inheritance. I've never been able to see any case in which multiple
inheritance was a really good solution - except where it as basically
just a kludge around a static typing system.)

>>I haven't seen a strong typing system yet that doesn't require you to 
>>(hopefully carefully) circumvent it at times ...
>
>And I, in turn, have never seen an automobile in which it is not
>necessary to take off the seatbelt occasionally, even when driving.
>That doesn't mean that seatbelts are counterproductive.
>
>We've all heard the stories of people who drowned in their submerged
>cars because they couldn't unfasten their seatbelts.  But such
>anecdotes leave unmentioned the thousands of lives that are lost in
>mundane accidents, lives that could have been saved if only seatbelts
>were used.  Arguments against static typing are often based on similar
>anecdotal evidence; such arguments are similarly bogus.

A fine example of proof by analogy. And as usual, it doesn't prove
anything. Static typing is NOT a seatbelt. Dynamic typing is NOT less
safe than static typing. 

I've said the following several times, but just in case it hasn't
sunk in yet:

Any typing error that would be trapped in a staticly typed language
can be captured in a dynamically typed languages using dataflow
analysis. If the error can't be caught with dataflow, then either
the program would be written differently in the static language (in
which case, the same safe version could be written with the dynamic
typed language), or the staticly typed language would have a kludged
dynamic typer, in which case the static language would be as subject
to error as the dynamic.

>Chip Salzenberg at Teltronics/TCT     <chip@tct.uucp>, <uunet!pdn!tct!chip>

	<MC>

-- 
---------------------- Mark Craig Carroll:  <MC> ------------------------
------ U of Del. Grad Student in CIS ------ EE/CIS LabStaff Hacker ------
-- Resident Wierdo @ 105 E Cleveland Ave, Newark DE - carroll@udel.edu --
---------------------- Shalom Achshav - Peace NOW! ----------------------

alms@cambridge.apple.com (Andrew L. M. Shalit) (04/03/91)

In article <27F11D7B.6309@tct.uucp> chip@tct.uucp (Chip Salzenberg) writes:

   According to rick@cua.cary.ibm.com.UUCP (Rick DeNatale):
   >I'm actually a little bit surprised that people put so much faith in compile
   >time type checking systems that they are willing to accept an implementation
   >that allows type errors that escape the compiler to cause wild branches and
   >other unsavory acts ...

   Please note!  The C++ type system does, in fact, prevent such type
   errors -- UNLESS the programmer lies to the compiler about the type of
   an object.  Such lies are entirely the programmers fault, and do not
   reflect badly on the language.

That's a very good point.  If programmers could just get out of the habit
of putting bugs in their programs, all kinds of programming tools would
become unnecessary.

Unfortunately, most programmers seem to want to keep putting bugs in
their programs.  Maybe they just do it for sentimental reasons, or
maybe it's something to do with job security.  But I agree with
Chip, there's no reason for a programming language or environment
to do anything to help such stubborn people!

   -andrew