strong/weak typing and pointers

Steven Bethard steven.bethard at gmail.com
Tue Nov 2 17:18:34 EST 2004


Christophe Cavalaria <chris.cavalaria <at> free.fr> writes:
> 
> One could say that the common definition of weakly typed languages cannont
> apply for a dynamicaly type language. Let's face it, once you've
> implemented a dynamicaly typed language, it seems very hard to use one
> piece of data as the wrong type.

While I agree that it would be kind of foolish to implement a dynamically typed
language that wasn't strongly-typed (PL theory definition), there's no reason
you *couldn't* -- your language would just need to provide some sort of 'cast'
function that did the conversion at runtime.

For example, say the memory block for an object instance was allocated like:

[0] pointer to class object
[1] pointer to dictionary object (holding variables)

Then maybe you could do something like:
  int1, int2 = cast(object(), list(int))
Given, I can't see any use for such behavior, but you *could* do it if you had a
weakly-typed dynamic language and you knew how it allocated objects.  At some
level, you always have bits -- whether it makes any sense to reinterpret them
depends on exactly what the bits originally meant.

> What we can do is extend the definition of weakly typed language to something 
> like : "A weakly typed language is a language that often uses incorectly some 
> piece of data by applying to it the wrong type" Such definition would include 
> any language that is too liberal with the type coertion like php.

Don't get me wrong -- I do understand your point.  In every case I can think of,
there is no reason to want weak-typing (PL theory definition) in a
dynamically-typed language.  On the other hand, I haven't really seen any good
cases for wanting weak-typing in a statically-typed language either.

Note that PHP doesn't fit your definition above anyway.  When PHP allows:

"a" + 10 == 10

it's not incorrectly using "some piece of data by applying to it the wrong
type".  It's doing exactly what it tells you it'll do.  This is *correct*
response given the PHP language definition.

In addition, you *can* create a statically-typed language that is strongly typed
(PL theory definition) but also very liberal with type coercion.  What would you
call such a language?  Since being liberal with type coercion and allowing bit
reinterpretation are orthogonal, why not keep the two separate terms?

My issue here is that I don't think we should confuse an already easily confused
term by giving it a second meaning.  If there aren't any dynamically typed
languages that are also weakly-typed, that's ok -- it doesn't mean we should
change the meaning of "weakly-typed" for these languages.

Steve




More information about the Python-list mailing list