Why does Dynamic Typing really matter?!?

Kaz Kylheku kaz at ashi.footprints.net
Thu Feb 6 12:49:54 EST 2003


chastel_pelerin at hotmail.com (Jason Smith) wrote in message news:<623cd325.0302060257.1542e098 at posting.google.com>...
> Hi All
> 
> I'm doing some research into language constructs, particularly dynamic
> typing.  What I'm looking for are examples in dynamically typed
> languages that clearly illustrate the benefits that dynamic typing
> give to a solution to a problem.  I'm aware that dynamic typing
> provides the following,
> 
> But what I want need is an solution to a problem that would not be
> possible to replicate in a statically typed language...

This is impossible, because of a little piece of theory known as
Turing completeness.

Any two languages that have the same level of access to the platform
in which they are running, and are both Turing complete, can---in
principle---solve all of the same problems, to the point that two
different programs written in one and the other exhibit identical
externally-visible behaviors.

However, one program may be significantly more complex, larger, and
much more difficult to understand, let alone maintain.

Dynamic typing allows programmers to write much smaller, more
expressive code.

It really is necessary; it's not just some tool that you can pull out
to solve a specific type of problem. It's generally useful in every
nook and cranny in a large program.

Compile-time declarations of type should be the exception, rather than
the rule! Static typing is an optimization technique---it lets the
compiler banish some of the run-time type information from the
representation of an object, and generate tight machine code.

There are all kinds of situations in which you don't care about the
type of an object, and want a variable that can represent any type.
For example ``shim functions'' that are interposed between two layers
in a program may just want to transparently communicate whatever those
layers want to say to each other.

Static typing is like having a specialized road for nearly every kind
of vehicle. Motorcycles go on this type of road, minivans go here,
large trucks go here, sub-compact sedans here, and so forth. You end
up with horrible inconveniences; there is way too much pavement
everywhere, and you can't go wherever you want in a straightforward
way. To get from point A to point B, you have to do stupidities, like
changing vehicles several times, wrapping your car inside a truck to
smuggle it through a trucking road, making several motorcycle trips
back and forth to get your goods across some point, and so forth.

It's a lot better to have a generic road shared by everyone. There are
fewer roads, and no artificial inconveniences.

> Can anyone pt me in the right direction or provide a small example?

How about the stupid circle-ellipse problem that OO flunkies like to
discuss over coffee?

This goes away even for mutable objects, when you have a dynamic type
system that lets you adjust the class of an object during its
lifetime.

The circle and ellipse really have two types: the manifest type
assigned by the programming language (which is invariably assumed to
be Java or C++) and the understood type which comes from the numeric
relationship of the object properties.

The whole crux of the matter is that the member variables of ellipse
can be mutated such that its understood type becomes ``circle''; but
the manifest type does not change. The programming language can fix
that: adjust the manifest type to match. The object then becomes a
language-level circle as well as a de-facto circle, and so methods
specializations over circle are now activated for that object for as
long as it remains a circle.

That would be an extreme example of the application of dynamic typing:
not all dynamic type systems support changing type at run time.




More information about the Python-list mailing list