top | item 47209375

(no title)

curiousgal | 9 hours ago

I can't help but find type hints in python to be..goofy? I have a colleague who has a substantial C++ background and now working in python, the code is just littered with TypeAlias, Generic, cast, long Unions etc.. this can't be the way..

discuss

order

maleldil|3 hours ago

> TypeAlias, Generic

This is mitigated by modern (3.12+) generic and `type` syntax, which just looks like any other static language.

tialaramex|8 hours ago

Typing is a relatively easy way for the human author and the machine to notice if they disagree about what's going on before problems arise. It is unfortunate that Python doesn't do a good job with types, I was reading earlier today about the mess they made of booleans - their bool type is actually just the integers again.

nubg|8 hours ago

> I was reading earlier today about the mess they made of booleans

Can you elaborate on that?

wiseowise|8 hours ago

What is the way in your opinion?

IshKebab|9 hours ago

I strongly disagree. Python has actually done a decent job of adding type annotations into the language IMO.

If you ignore the bit where they don't actually specify their semantics anyway.

> this can't be the way..

The alternative is fragile and unmaintainable code. I know which I prefer!

b00ty4breakfast|1 hour ago

the alternative should be using a real statically-typed language instead of glorified comments that don't do anything without outside tools.

I understand that very large code bases have been built in python and this is a compromise to avoid making them rewrite Ks upon Ks of LoC but as it stands, Python type annotations are akin to putting a Phillip's head screwdriver on a ball peen hammer; the screwdriver is not a real screwdriver and the ergonomics of the hammer have been compromised.