Static Typing in Python

Jacek Generowicz jacek.generowicz at cern.ch
Wed Mar 17 16:44:56 EST 2004


JCM <joshway_without_spam at myway.com> writes:

> Jacek Generowicz <jacek at lxplus057.cern.ch> wrote:

> which implies "weak typing" means there's the possibility of treating
> a piece of data as the wrong type.

Yes, consider

   "3" + 3

In languages that do not consider the above to be an error, you will
probably get "33" or 6 as the result. Whether one of those pieces of
data is treated as the wrong type or not, depends on your intentions.

> The FOLDOC definition
> 
>   http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?query=weak+typing
> 
> which mentions things like
> 
>   int a = 5;
>   float b = a;
> 
> to me doesn't have anything to do with weak typing, since the int is
> correctly converted to a float.  I guess thay're calling it "weak
> typing" because the cast is implicit.

Yes, and the more implicit type conversion a language does, the more
likely it is to get it wrong (because what is correct depends on the
programmers intention), therefore there is a greater likelyhood of
getting the wrong result. Which is why I consider implicit type
conversions to be an aspect of weak typing. (However, I have no
problems with you not seeing it that way.)

If you don't call it "strong/weak typing", do you have an alternative
name to describe differences in how "easy going" a type system is?

Consider the following table.


            ML    Python   PERL

1.5 + 1     No     Yes     Yes

"3" + 3     No     No      Yes


ML is clearly stricter than Python, which is stricter than PERL. Do
you have a name for this sort of strictness ?



More information about the Python-list mailing list