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

Antoon Pardon antoon.pardon at vub.be
Tue Feb 20 08:04:29 EST 2018


On 20-02-18 13:11, Paul Moore wrote:
> On 20 February 2018 at 11:18, Antoon Pardon <antoon.pardon at vub.be> wrote:
>> Personnally I would prefer the type system of Pascal and Modula2 with
>> their interval type
>> above a Digit class in python. For the simple reason that once you had
>> declared a variable
>> like this:
>>     x: 1 .. 10;
>>
>> Each assignment to x would then implicitly do something like an assert
>> to checks the constraint,
>> so it would be impossible to ever assign 11 to x, without an error being
>> thrown.
>>
>> There is no such possibility in Python. You can off course start with x
>> = Digit(5), but the language
>> won't stop you from doing x = 11 later.
> All that is saying is that in Pascal, variables have types, whereas in
> Python values have types but variables (names ;-)) don't. It's true,
> but not particularly important in toy examples like this. In larger
> scale programs, tracking the "type" of what gets assigned to a
> variable can be really useful, and carefully managed types can help
> with this. Pascal/Modula2 (and C/C++) have the compiler do this,
> Python has a separate tool (MyPy).

In Pascal and Modula2 type checking was not limited to compile time. Part
of that type checking was done at by the runtime enviroment.

>> I'm not proficient with C++, but IIUC, you could make a class in C++ and
>> have the constructor and
>> copy operator check for these kind of things. True it would be run-time
>> checks but that would
>> already be more than Python can give.
> That (run-time checks) is exactly the same as Python gives.

No it isn't exactly the same. Those runtime checks are implicit. They are like
a contract made at declaration time, which make it impossible to assign something
to the variable that doesn't meet the constraint without the program throwing an
error.

You can't do something like that in Python.




More information about the Python-list mailing list