static, dynamic, strong and weak (was RE: PEP 285: Adding a bool type)

Ken Seehof kseehof at neuralintegrator.com
Wed Apr 10 09:49:30 EDT 2002


> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Alex Martelli
> Sent: Wednesday, April 10, 2002 3:34 AM
> To: python-list at python.org
> Subject: Re: static, dynamic, strong and weak (was RE: PEP 285: Adding a
> bool type)
> 
> 
> Ken Seehof wrote:
>         ...
> > as a float, int, longint, or bool, depending on context.  All numbers
> > of equal value are pretty much interchangable (this becomes more true
> > as we add more numeric unification features).  In c/c++ numbers are
> > more strongly typed, in that there are many ways to get error messages
> > for using the wrong type of number without explicit conversion.
> 
> I disagree.  For example, in C I can use a float to index into an
> array and get it converted to an int implicitly and silently; in
> Python, using a float to index into a list is a TypeError.  What
> kind of compensating examples do you have in mind, where C would
> be stricter than Python "for using the wrong type of number"?

Not with my compiler...

  float x = 1.0;
  int a[4];
  a[x] = 4;

  error C2108: subscript is not of integral type

Hmm.  I thought you could do that in python, but I was wrong too...
Actually I was expecting the exact opposite of what you suggested.

Sequence indexing fails, but dictionary indexing works:

a = {}
a[2.0]=5
a[2]
5

But then this isn't a good example since C doesn't have dictionaries.
Hmm.  When I really think about it, I can't think of any.

You win.

> > The fact that an object's type doesn't actually change seems like an
> > implementation detail to me.  Numbers in python -feel- as if they are
> > weakly typed.
> 
> Not to me.  Even in Haskell I can write 1+2.0 - and Haskell is the
> strongest-typed and feeling-strongest-typed GOOD language I know
> (let's PLEASE forget that unnamed language where you must use + only
> to add integers and +. to add floats... have they changed it yet?-).
> 
> The first time I (accidentally) used a float as a list index and
> got a TypeError has impressed Python on me as strongly (albeit 
> dynamically)
> typed, better than any other study or experience so far.
> 
> 
> Alex

Well, after the grand numeric unification, (python 3.0 right?) you
will be able to index by float if the value is exactly equal to
an integer.  But C/C++ still will not permit it.

- Ken






More information about the Python-list mailing list