[Tutor] Should I use type hints for all new code?

Alan Gauld alan.gauld at yahoo.co.uk
Fri Aug 25 17:59:57 EDT 2023


On 25/08/2023 15:03, Simon Connah via Tutor wrote:
> I'm wondering if I should use type hints for new code. 

I'm probably in a minority here but I avoid type hints and dislike
them intensely.

I spent a large part of my professional life as a maintenance
programmer on statically typed languages(mainly Pascal ad C/C++)
And static typing resulted in probably the second biggest cause
of bugs after uninitialised pointers. It's not the typing per se
but the resultant need for (often unnecessary) type conversions
to conform to the types. And type conversions are a huge
potential source of errors (and usually intermittent and
very hard to find!).

I think type hints go completely against the principles of dynamic
typing (of which I'm a big fan). Thankfully, in Python they are
only a hint and can be safely ignored, although I'm dreading
the day somebody decides to make the interpreter pay heed to them!

I know that goes against the orthodoxy and certainly what
I was taught in school. But in the real world I find static
typing to be more of a problem than a help. Embrace dynamic
typing. If it acts like a duck it is a duck.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos





More information about the Tutor mailing list