[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: another take on hackers and painters




As I see it, the freedom you get from dynamic type systems is the freedom
not to have your valid program rejected because it doesn't type check.
It's not hard to come up with examples:

(define (return-int-or-string x)
   (if (< x 0)
       0
       "nonzero"))

This will not type check in any static language I know of (although you can
define a type in ocaml that does something pretty close to this).  If you
use this in a context in which x is *always* an integer, and the return
type is expected to have different types depending on x (int or string),
then you can write valid programs that use this procedure.  But most
statically-typed languages won't let you.

More to the point: I had something of a falling out with ocaml when I
realized that an application I wanted to use it on really needed
multimethods (or at least the ability to fake them).  There was no way to
fake multimethods in ocaml without a huge amount of pain.  It's pretty easy
to implement a multimethod system (or at least to fake it) in a dynamic
language.  This is one of those rare cases that Shriram mentioned where the
type system bites you. ("Bite me, ocaml type system!" ;-)) Interestingly,
you can fake multimethods in both java and C++ *without* inordinate pain
(using run-time type identification).

I still like static type systems for the correctness checking and
efficiency advantages they provide, but sufficiently sophisticated
applications stand a good chance of overwhelming sufficiently
unsophisticated type systems (which is why advanced type system design is
such a hot topic among CS researchers, and which interestingly gets into
all sorts of hairy theoretical stuff like undecidability).

Mike

P.S. It's important to realize that preferences in type systems, like
preferences in programming languages, are very much a function of the
personality of the programmer.  Some programmers can't stand to program in
anything other than C, or perl, or lisp, or python, or smalltalk.  Arguing
that one way is right or wrong is not terribly useful; we can all get
along.  Talking about *why* you favor one type system/language is more
interesting, as long as everyone keeps an open mind.


> From: mcguire@cs.utexas.edu
> Date: Tue, 20 May 2003 15:15:22 -0500
> 
> > Clerical programmers [...] will not know what to do with the freedom
> > given by things such as dynamic typing.
> 
> Ok, so I'm none too bright.  What exact freedoms do you get with dynamic
> typing?  It seems like a type problem is going to result in a broken
> program either way, so you still have to think about types and making
> sure the right collection of stuff gets put in the right place.  The
> only real advantages I can see are:
> 
> * A dynamic type system makes the language implementation easier.
> Writing a decent static type checker is harder than a decent dynamic
> type checker.
> 
> * Macros:  I know staticly typed macro-ish systems exist, but with the
> execption of camlp4, I don't know of any that are a standard part of a
> language or even a standard part of an implementation.  Again, dynamic
> typing makes it easier, better integrated, and thus more common.
> 
> 
> Tommy McGuire
>