strong/weak typing and pointers

Diez B. Roggisch deetsNOSPAM at web.de
Tue Nov 2 12:58:53 EST 2004


>> Strong/weak typing is about how much you care of types at all - in php,
>> its perfectly legal to add strings to numbers - the string simply gets
>> converted to a number beforehand, that conversion yielding 0 when there
>> is nothing useful and numberlike can be extracted from the string. So
>> typing is weak, as it doesn't constrain the possible operations on
>> variables with certain values.
> 
> By this definition, Python is also weakly typed:
> 
>>>> 2.0 + 1
> 3.0

I'm not sure how things are implemented internally, but I'd still say my
definition is correct even for this example: The + operator can be viewed
as overloaded with the signature

(float, int) -> float

But its not for (string, int) - albeit * e.g. is. 

> The point here is that I consider C weakly typed because, with no error of
> any sort, it allows me to reinterpret a block of memory in as many ways as
> I like.
> A strongly typed language like Python does not allow this.  Even in my
> Python example above, we're not *reinterpreting* the block of memory
> representing 1 as a floating point value; we're *coerceing* the integer 1
> into the floating point value 1.0 (which probably means allocating a new
> float variable at the C level) before performing the addition.

This is definitely weak typing. 

The question remains if permanent coercions as php (and afaik perl) do can
also be considered weak typing, as you won't end up with an error for more
or less anything you do.

I say yes, but maybe thats a matter of taste.


-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list