Adding static typing to Python

gbreed at cix.compulink.co.uk gbreed at cix.compulink.co.uk
Thu Feb 21 08:05:48 EST 2002


Erik Max Francis wrote:

> 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).

At the point you describe C as strongly typed, you've lost me.  With this 
code

int main() {
        printf("%i", *"\100\0\0\0");
}

I get

$ make typetest
gcc     typetest.c   -o typetest

$ ./typetest
64

Every object in C is a "manipulable region of storage", and can have 
whatever type you want.  How could they have any weaker intrinsic types 
than this?  

As for Perl, from the top of perldata we have

"""
Perl has three built-in data types: scalars, arrays of scalars, and 
associative arrays of scalars, known as ``hashes''. 
"""

So it *does* have strong typing, but describes different things as "types" 
to what you assumed.  Further down, it even says

"""
Although strings and numbers are considered pretty much the same thing for 
nearly all purposes, references are strongly-typed, uncastable pointers 
with builtin reference-counting and destructor invocation.
"""

Okay, so we have a continuum and Perl isn't quite purely weak typing.  But 
I still don't see a trace of strong typing, by this definition, in C.  I 
can also find plenty of contradictory definitions ...


                    Graham

        <http://www.microtonal.co.uk/>



More information about the Python-list mailing list