4 ms·
I inherited a python based build system which had been written without any unit tests because....it's a build system right? right?? Anyhow it was the kind of t
by t43562 4y ago
I inherited a python based build system which had been written without any unit tests because....it's a build system right? right?? Anyhow it was the kind of thing where you'd build for 20 minutes (Android) and then have some kind of trivial error in the python code at the end of the build. You fix that and run again and waste another 20 minutes on the next thing.
I couldn't do unit tests all at once because of the design not having any way of accommodating them. I needed something to stop the enormous waste of time.
So I added type hints. The IDE should show me when illogical things were being done with parameters to methods/functions. It was fairly quick compared to a total refactoring but not effort free. I barely noticed any effect. Didn't catch a single error. Eventually I created a kind of dummy version of Android that "built" in a few seconds and I tested against that first. That allowed me to speed up changes and get some refactoring done to make a few critical unit tests and the whole thing started to get under control.
This anecdote has almost no meaning - you cannot conclude that type hints have no benefit because of one case - I just think that tests are almost always more important and hinting and the whole rigmarole of strong typing are much less of a panacea than tests are.
- atorodius 4y agoIMO type hints are mostyl about (significantly!) improving readability.
- aldanor 4y agoAlso about improving editor experience and having better auto-completion that's based on type hints.
- ElectricalUnion 4y agoPyCharm and VSCode can do a lot of reasonably smart refactorings when the code isn't just a pile of `typing.Any` and that's a huge quality of life for any non trivial code base.
- MrJohz 4y agoAgain, purely anecdotally, I've done similar things in both Typescript and Python, and I usually catch at least one silly type error in Typescript, but I rarely do in Python. That could be because the Python developers I was following were just so good, but I suspect it's more about the quality of the typecheckers. Typescript feels much better at finding errors in normal, idiomatic Javascript, whereas I feel that with Mypy, if I want the best results, I need to write code in a way that plays to its strengths. I've been told that Pyright is better but I've not tried it out properly. But yeah, your experience largely matches with mine, for Python at least.