logoalt Hacker News

Twirrim • yesterday at 6:27 PM • 1 reply • view on HN

I've been writing python for closing in on two decades (I want to say maybe 2.5 was my introduction point?).

I've found type hints to be remarkably useful and catch significantly more bugs than I ever would have thought, and have quickly picked up the practice of using them wherever I code. My general finding is that if I have to struggle to put useful type hints in place, I probably need to rethink my code.

I even type hint my unit tests because I've learned that sometimes type incorrectness means my tests haven't been testing what I thought they were testing.

Frameworks like pydantic[0] can help you turn those type hints into something runtime enforcing too.

[0] https://pydantic.dev/docs/validation/latest/get-started/


Replies

ReflectedImage • today at 12:24 AM

Generally speaking, static typing is the great enabler of writing bad Python code.

As soon as static typing is introduced into a Python code based, the developers start writing unscalable coding patterns that don't scale to larger programs.