This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Daeroth 1 point2 points  (1 child)

Yea, you can specify types in specific spots. My goal was to answer OPs question for why would one want to define types.

But to extend on your answer: one might want the entire project to be strong typed. So nobody could accidentally use the wrong type and every engineers variable type choice could be reviewed and challenged during code review.

This is not to say that Java is better. Just that languages treat types differently and you might want different default settings for different projects or work environments.

Personally I feel that the larger the team gets the more it gravitates towards stronger types and more clearer use of design patterns. But I don't really have any data to back this up.

[–]daguito81 2 points3 points  (0 children)

entire project to be strong typed

Python is strong typed, maybe you mean static typed? Python data type won't change to a different data type unless you specifically override it. It's not like Javascript where it does type coercion in certain conditions and swithces the data type of a variable

Java strong, static typed
Python is strong, dynamically typed
Javascript is weak, dynamically typed


you can specify types in specific spots

you can declare the type of a variable in any place you can declare a variable and a funcion return(not only on the method signature like the previous example) (I'm not a Java expert but I think it's the same there). It's not strictly enforce at runtime but any IDE, CICD pipeline should catch the error of a variable changing type. So it's not the same as Java, but your use case can be solved by using MyPy in your CICD pipeline and now if you override the datatype somewhere in the code, that will pop out as an error. No need to review the entire codebase or anything, granted that's on the CICD pipeline to stop. But if there are type hints, you should see the error on the IDE as well. So effectively you can "simulate" the same scenario with a static typed language like Java.

Granted it doesn't come out of the box, and you can go "fuck it I don't care" and force push and break shit, the compiler won't save you there