Frustrations without static types
April 13, 2020
Recently I was working on a piece of my company’s Python code base that I hadn’t touched before. It was part of an automation script that makes some API calls to GitHub using the Requests library.
I needed to check some of the parameters on the response, run some different functions based on the response code and various other checks. But without static types, there was no easy way to know exactly what parameters the response object had. Surely it had a status code of some kind right? But was it:
Without static types there was no easy way for me to know. Even if I happened to remember that for this specific library the answer is
response.status_code, is it a number? Is it a string? What about other values on the response? In order to figure all this out, I had to dig into the docs and source code of the requests library.
Clearly static types are not the only thing to consider when picking a language, but this is a clear, albeit simple, example of some frustrations of when you don’t have them.