Python from Wise Guy's Viewpoint

Don Geddis don at geddis.org
Tue Oct 28 11:57:34 EST 2003


Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl> writes:
> You make some array of doubles, set a[i] = exp(i) (a double) and it works.
> Then you set a[i] = 2*i (an integer) and it still works, because the
> integer has been converted to double during assignment. An integer can be
> used in place of a double with the same value.

Surely in a "proper" staticly typed language, you can't assign an integer
to a variable declared (floating point) double.  Shouldn't that be a type
error?  (Unless you do an explicit cast, of course, but then the programmer
made the decision, not the language.)

> Now in a dynamically typed language the analogous code would set some
> array elements to integers without conversion. If division on them means
> a different thing, an integer can no longer be used in place of a floating
> point number with the same value. And division is the only operation whith
> breaks this.

Why would division on integers mean something different than division on
(floating point) doubles?

> Dynamically typed languages shouldn't use / for both real and truncating
> division. For statically typed languages it's only a matter of taste (I
> prefer to use different symbols), but for dynamically typed languages it's
> important to prevent bugs.

In Lisp, "/" always means the same thing.  It's never a truncating operation.

This doesn't seem to be related to static vs. dynamic typing.

        -- Don
_______________________________________________________________________________
Don Geddis                  http://don.geddis.org/               don at geddis.org
Football combines two of the worst things about American life.
It is violence punctuated by committee meetings.
	-- George Will




More information about the Python-list mailing list