Should i annotate types in my unit tests functions? What also with overridden django methods like save and get or post functions in generic view?
-
@WillemVanOnsem I mean though, you could have that response to pretty much any question on this site.– NeilCommented Aug 8, 2019 at 10:02
-
@Neil: most questions on these site are "why is my code not working", so then it is not much opinion based :). Furthermore a lot of questions have definitely some theoretical foundation. For example certain logic programming semantics are better than others based on the "well founded semantics".– willeM_ Van OnsemCommented Aug 8, 2019 at 10:08
-
I agree that this might be opinion based. The best approach though if you think that is probably just to mark it as opinion based and vote to close.– NeilCommented Aug 8, 2019 at 10:21
1 Answer
This is arguably an opinion question but I think that there is a generally accepted answer, which is roughly "No".
One way of categorising programming languages is into statically typed and dynamically typed. Statically typed languages are generally more robust, especially for "programming in the large", and dynamically typed languages have advantages ito programming speed, and in modelling problems where it is beneficial to be able to accept data of various types. Type hints try to strike a balance. The rough rule being: if you are using the dynamic nature of the language to achieve something, don't worry about annotating it. If however, you are writing code that doesn't make specific use of the dynamic nature of the language, annotate
Perhaps to make the point clear, consider that if you DO annotate everything, well then why not just use Cython? Same effort but you actually get some speed up as well. The reason people use Python with annotations instead of Cython is that some problems are naturally better solved without specifying types.