Remix.run Logo
wk_end 3 hours ago

Yeah, the idea that types exist just to help the compiler catch your mistakes shows a depressingly superficial understanding of the benefits of static typing.

Types exist so that the compiler can reason about your code better - but not incidentally, they also help you reason about your code better!

To wit: even when working in dynamic languages, it's often considered a good practice to write down in docstrings the types of objects a function can operate on, even without static enforcement. Thinking about types is helpful for humans, too.

And it's not even just a thing to help you read code in the future - types help me write code, because as I sit down to write a function I know the possible values and states and capabilities of the object I'm working with. In the best of cases I can analytically handle all the possible cases of the object, almost automatically - the code flows out of the structure of the type.

bossyTeacher 42 minutes ago | parent | next [-]

> Types exist so that the compiler can reason about your code better - but not incidentally, they also help you reason about your code better!

THIS. So much. This observation is extremely intuitive to me.

smohare an hour ago | parent | prev [-]

[dead]