Are you a lazy developer like me?
Probably. Many developers got into programming to do a thing automatically they didn't want to do manually anymore.
This often shows in the lack of comments, variable names
i, j, x, y, bla, test, docstrings, and of course type hints.
What's a Type Hint?
Just to quickly catch everyone up.
In Python you can change variables on the fly and in many cases Python will even make the intuitive conversion. In computer science, we call that "not being statically typed". Computer scientists love static types, because they make it very clear what is being passed around in a program and you can use programs to check what you've written. Dynamically typed languages make that a bit harder.
You can do this while assigning a variable, i.e.
five: int = 5
or in a function signature, even defining the output.
def is_five(data: int) -> bool: return data == 5
Why We Ignore Type Hints
Type hints are great in big production code. They're mostly used by static type checkers like
But they don't do anything in the code. They feel like wasted characters.
Nothing more annoying than being inefficient and making you write more, right?
What's more is that you have to be intentional about you thought model for your program. It takes extra brain cycles to think through what each variable is supposed to be.
Making the mental model of a program explicit rather than implicit can be hard work.
How I Finally Started Using Type Hints
The case for type hints, other than making your software engineer happy, is readability of code. Even without a proper docstring, the code is suddenly very clear about what variable expects which input type. I have returned to code many times and thanked myself for annotating variables.
Little detour, but trust me here. I love docstrings, but they are a lot of boiler plate and I can never remember which part goes where. So obvisously the VS Code Extension AutoDocstring is among my favorites. (Here are my favourite 10 extension in fact.)
This docstring generator is magic, taking most of the work out of my hands. I mentioned, I'm a lazy dev, right?
And then I figured out that it will take your type hints and automatically fill it into the generated docstring.
Suddenly, I'm writing type hints in every function signature.
Just so I don't have to do it by hand in a docstring.