Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!snorkelwacker.mit.edu!ai-lab!life!tmb From: tmb@ai.mit.edu (Thomas M. Breuel) Newsgroups: comp.lang.misc Subject: Re: Dynamic typing (part 3) Message-ID: Date: 29 Apr 91 06:28:52 GMT References: <2450@optima.cs.arizona.edu> Sender: news@ai.mit.edu Organization: MIT Artificial Intelligence Lab Lines: 55 In-reply-to: gudeman@cs.arizona.edu's message of 26 Apr 91 00:19:41 GMT To repeat: weak typing means that the language may have undefined behavior like infinite loops or core dumps from a type error. Dynamic typing means that it is not generally possible to assign a machine representation to the values that will be returned by all syntactic expressions. You can still get strong typing in this case by including type information with the data at runtime. Conversely, you can also get dynamic typing in statically typed languages by creating unions ("datatype" in SML). At least in a language like SML, the static type system is an additional, very useful facility offered by the compiler. Most people who program in statically typed languages write dynamically typed code in some places; they simply restrict it to particular sections of their programs. Unfortunately, the notation for expressing dynamic typing in many statically typed languages is a little cumbersome, requiring explicit tagging and untagging by the programmer. However, C++, because of user-definable conversion operators, lets you use dynamic typing a little more easily, and ECL (an old Lisp-like language) had an even smoother integration of dynamic and static typing. It means that most programs are smaller and simpler in dynamically typed languages than in statically typed languages. Dynamically typed programs are also impossible to prove type-correct, and many trivial errors go unchecked. It is not all that hard to show this: just compare the size of all the .h files in C programs to the total size of the program. As a rough approximation, the .h files are the extra baggage caused by static typing. That is a very rough approximation though, since dynamic typing enhances reusability of code. So a lot of reduncancy in the .c files should be eliminated also. As in most fields of human endeavour, redundancy is something to be aimed for, not something to be eliminated, since it helps catch mistakes. >>Type inference has some nice features, but it does _not_ give you the >>expressive power of dynamic typing. Dynamic typing is necessary for serious program development, since there are some things that are simply too cumbersome to express in a static type system. However, dynamic typing should not be the rule. For the proverbial "99%" of all programming tasks, static typing is more robust, and sufficiently expressive (at least, if it is polymorphic). As a bonus, statically typed languages tend to be easier to compile into efficient code with current compiler technology and machine hardware. Thomas.