Adding static typing to Python

Erik Max Francis max at alcyone.com
Wed Feb 20 13:16:14 EST 2002


gbreed at cix.compulink.co.uk wrote:

> Do you have a reference for this terminology?  I haven't seen it
> outside
> of comp.lang.python.  The only definition I have to hand contradicts
> it:
> 
> <http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?query=strong+typing>
> 
> "Strict enforcement of type rules with no exceptions. All types are
> known
> at compile time, i.e. are statically bound. With variables that can
> store
> values of more than one type, incorrect type usage can be detected at
> run
> time."

There seems to be some consensus (we had exactly this discussion in
#python on IRC) that Foldoc is inaccurate here (and, unfortunately, is
no longer updated).

Strong typing simply means that objects have an intrinsic notion of type
and that operations on them have different meanings depending on their
types.  Weak typing is the reverse; objects (or variables) do not have
any intrinsic type and the operations that are performed determine the
type.  Obviously there are varying degrees of strong typing; C++ is more
strongly typed than C, for instance, but both are strongly typed. 
Python is strongly typed; Perl would be a good example of a weakly-typed
language (e.g., 2 + 2 and 2 . 2 mean different things because "2"
doesn't have any intrinsic type).

In static typing, however, variables must be declared with a given type
and only objects of that type can be placed in those variables.  Dynamic
typing makes no such restrictions; a variable is a variable and can
refer to any type object, and can even be substituted with a different
type of object.

When strong typing is coupled with dynamic typing, typically it's
referred to as manifest typing.  Python and Common Lisp are examples of
this.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Laws are silent in time of war.
\__/ Cicero
    Esperanto reference / http://www.alcyone.com/max/lang/esperanto/
 An Esperanto reference for English speakers.



More information about the Python-list mailing list