Are the critiques in "All the things I hate about Python" valid?

Chris Angelico rosuav at gmail.com
Mon Feb 19 04:14:32 EST 2018


On Mon, Feb 19, 2018 at 7:40 PM, Alain Ketterlin
<alain at universite-de-strasbourg.fr.invalid> wrote:
> Tim Delaney <timothy.c.delaney at gmail.com> writes:
>> C is statically and weakly typed. Variables know their types at compile
>> time (static typing). It is a feature of the language that you can cast any
>> pointer to any chunk of memory to be a pointer to any other type (normally
>> via void *). This is not coercion - it takes the bit pattern of memory of
>> one type and interprets it as the bit pattern for another type, and is weak
>> typing.
>
> No. C has much stronger rules, not on casting, but on accessing the
> pointees, which basically invalidates your argument. Refer to the C
> standard for details.

Really? What rules?

$ cat demo.c; gcc -Wall demo.c; ./a.out
#include <stdio.h>

int main() {
    float f = 3.14159;
    int *i = (int *)&f;
    printf("As an integer, %f is %d\n", f, *i);
    return 0;
}

As an integer, 3.141590 is 1078530000
$

Looks to me like C is perfectly happy to interpret a float as an int.
What rules are you seeing violated here?

> But you can modify the class (not __class__) in whatever way you want.
> For instance:
>
>     class X(object):
>         def f(self): ...
>     ...
>     del X.f
>
> So, in Python, knowing that object x is an instance of class X tells
> you... essentially nothing. Call this strong typing if you want. In
> terms of type systems, it is (strong) simplistic-typing based on type
> labels, and labels carry no information whatsoever.

Sure you can. And you can do a lot of other things at run time, too.
Monkey-patching doesn't change the fact that x really and truly is an
instance of class X, it just changes what you can do with that object.
So what you're saying is that Python's dynamism makes it possible to
disrupt duck typing. Sure, I'll grant you that. But the type system
itself isn't broken by that.

ChrisA



More information about the Python-list mailing list