3 ms·
> I have friends who claim they cannot write code without static types and that JavaScript is unusable. What are their reasons?
by kraftman 7y ago
> I have friends who claim they cannot write code without static types and that JavaScript is unusable.
What are their reasons?
- DonaldPShimoda 7y agoSame problem with all dynamically-typed languages, really. It's too easy to write the wrong thing and not find out about it until you've written umpteen unit tests. This can happen due to typos, refactoring, or whatever else. Only JavaScript is worse because it's weakly typed too, so it performs implicit coercions in an effort to make your code always do something (meaning your unit tests have to be very good to really ensure your functions do what you think they do). A static type system ensures that, at the very least, all the types line up at compile-time. You find type errors much faster than with a dynamically typed language, and this can guide a much less exhausting development cycle.
- McWobbleston 7y agoPersonally, I have a bad working memory and struggle to remember the structure of data. I constantly have to jump around and try to find the name of things / recall their hierarchy With static typing I can just highlight a type / jump to the definition or get intellisense. I also find it useful when I have specific names for data types because I can reason about things / communicate them easier To me taking the time to specify types or wrangle the type checker is worth the reduced mental burden of having to remember the shape of things, and refactor data structures confidently
- bjourne 7y agoDynamically typed languages are perhaps not as easy to program in as thought. You need a lot of practice in naming things to produce readable code. For example, in Java it doesn't matter if the count of items is stored in a variable named 'n' or 'f'. The type would still be int. In Python, 'f' would be a confusing name, but 'n' would be acceptable.
- Adamantcheese 7y agoThat's basically my reasoning as well. I want the IDE to tell me things so I don't have to look up documentation all the time, especially since most of the time I'm working on code I had no part in originally. It's a helpful learning tool more than anything else.