PEP 526 - var annotations and the spirit of python

Bart bc at freeuk.com
Thu Jul 5 08:57:58 EDT 2018


On 05/07/2018 11:04, Steven D'Aprano wrote:
> On Thu, 05 Jul 2018 09:17:20 +0200, Christian Gollwitzer wrote:

>> Not sure what point you are trying to make, but your example compiles in
>> C, if you replace the '#' comment sign with '//'.

> Sometimes I wonder how C programmers manage to write a bug-free "Hello
> World" program. No wonder it is described as a type-unsafe language or a
> weakly-typed language.
> 
> I understand upcasting ints to floats, that's cool (even if a few
> languages take a hard line on that too, I don't). I understand Python's
> dynamic typing approach.

Do you? Python seems to have its own problems when mixing ints and 
floats: the calculation is done as float, that means converting int to 
float which can result in loss of precision when the int is bigger than 
about 2**52.

> I don't understand C requiring type
> declarations, then down-casting floats to integers.
> 
> At least it shows a warning.

You would need a warning both ways, since not all ints are representable 
as floats. And warnings when converting between signed and unsigned. Or 
from a wider int to a narrower one.

Programs would be so full of explicit conversions that real problems 
will be hidden, and they would be difficult to read.

Anyway lower level languages need more skill to write and you need to be 
very aware of what is going on.

-- 
bart


More information about the Python-list mailing list