Newsgroups: comp.lang.misc Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!barmar From: barmar@think.com (Barry Margolin) Subject: Re: Run-time Type Errors in Smalltalk Message-ID: <1991Apr18.035959.10795@Think.COM> Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge MA, USA References: <2023@optima.cs.arizona.edu> <8189:Apr1719:16:2091@kramden.acf.nyu.edu> Date: Thu, 18 Apr 91 03:59:59 GMT In article <8189:Apr1719:16:2091@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: >Goofus uses dynamic typing. Gallant uses static typing. ... >Management fires Goofus. > >Goofus says static typing catches so few errors that they probably all >_would_ be caught by testing. Gallant simply catches all the errors. > >Goofus finds 95% of the typing bugs during testing. Gallant finds 100%. > Goofus uses dynamic typing with automatic runtime type checking. Gallant uses static type checking, with no runtime type checking (except perhaps that explicitly programmed by Gallant, e.g. variant record discriminant examination). Goofus says static typing catches very few errors that aren't caught by runtime type checks during testing, and doesn't catch any of the errors that are not detectable statically (e.g. misuse of unions and pointer casting). Goofus finds 95% of the statically detectable typing bugs, and 95% of the non-statically detectable typing bugs. Gallant finds 100% of the statically detectable typing bugs, and 5% of the non-statically detectable typing bugs (the ones that happen to result in core dumps). The winner depends on the style of the program. Users of statically-typed languages often limit themselves (perhaps unconsciously) to using the subset of the language that is easy to check statically. Then they declare that dynamic checking isn't needed, because static checking is able to find all their type errors. I feel similarly about array bounds checking. Actually, I think a good solution is a compromise, a la Common Lisp and some polymorphic functional languages. The programmer may include optional type declarations, and the compiler should do type propogation. Where the compiler can prove type safety, it doesn't need to insert runtime type checks; when it can't, it puts in the checks. I've read about similar schemes for optimizing away most array bounds checks. -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar