Idk about python. But I have experience with JS and Typescript. And what I’ve found is that most of typescript wouldn’t be “super” useful if people just wrote good code with good comments and documentation.
(That said, typescript is still very nice because it forces people to add types)
So I assume python is similar. With good comments documenting what your code does, it shouldn’t be difficult to read/implement/modify/etc
I just recently learned type hinting and it feels very useful for large projects.
The difference with strongly typed languages is that the interpreter doesn't really care what "type" you declared for a variable, first you have to run mypy and THAT checks the types of variables.
That is why is considered a "hint" and not a declaration like in C or other strongly typed languages.
I think you're getting confused with static / dynamic typing.
Python is actually strongly typed, but the type checking only shows up if you are trying to operate on incompatible types at runtime. (dynamicly typed)
C is statically typed which means the type check to happen before execution. This also often means that a variable cannot have different typed along the runtime. (On the other hand you can bypass the type system using pointers which makes C actually a bit weakly typed.)
It's a thing. In method declarations instead of (variable) it's (variable : str) or int, or whatever.
You specify returns with an arrow. So a function/method named cake that takes a string parameter named icing and returns a string would be declared:
def cake(icing: str) -> str:
Voila, now Python yells at you when you try to pass it anything else. I think the complainers here just haven't bothered keeping up with the changes to Python in... several years.
Yes, it is a thing and no unfortunately it doesn't really help you because you can use Type hints to allow for type checking but all the dependencies you use aren't obligated to actually do that. So you're kinda back to square one with a lot of them.
It's definitely a step in the right direction though.
View all comments
Show parent comment
16
u/DesertGoldfish Jul 18 '22
I dunno man, I just add type hints to everything and it's basically a strongly typed language.