Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Correctness in Python is all about unit tests - if you don't bother with them then you're playing with fire (and of course I often "play with fire").

Type hints .... well they help the IDE to autocomplete which is great. They also help you to get the order of parameters in a function/method call correct which is useful if the parameters aren't all the same type!

I converted a medium sized project to type hinting once. The original author wrote no tests and obviously didn't design it to be testable so I was looking for some small way to make it less horrendously unmaintainable. Every test run of the source took hours and there would be some trivial syntax error or whatever right at the end.

Type hints weren't so difficult and I hoped that they would "staunch the bleeding" while I tried to get it into testable shape. In this case they did almost nothing - didn't help me stop a single bug - probably because most types were "str" but that's not the fault of the hinting system as an idea, right? It's just an unprofitable load of work in particular situations.

Static typing fans are always going to be disappointed by Python and it's great because there are other languages for them. For the rest of us we can use them where it turns out to be profitable to us.

Unit tests are, however, by 1000x, more important.



> Correctness in Python is all about unit tests - if you don't bother with them then you're playing with fire (and of course I often "play with fire").

But Python does support type hints, and tools like MyPy do use those type hints to evaluate correctness. It seems to me that Python's type hints are indeed Python's way to check for correctness.

Also, unit tests don't verify correctness. They only serve to check whatever small set of ad-hoc invariant developers put up.


You can have a program with correct type handling that doesn't work but with unit tests you have a program that works and documentation (in the form of the test) about the ways in which the programmer expected it to work.

That's why I find type hinting to be relatively high effort for relatively low benefit and choose to use it only where I feel it makes life better. The optionality suits me. It's a nice to have but that's all.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: