DEV Community

Discussion on: Why use static types in JavaScript? (Part 3)

Collapse
 
millebi profile image
Bill Miller • Edited

In non-trivial coding, type checking will always produce less idiotic buggy code (i.e. The bugs that are PEBKAC's) and will also reduce the number of "stupid" tests (Null/undefined failures, detect garbage input, etc...). So in almost all cases, having a compiler complain that you have a type wrong will help you in the long run.

Your point about it complicating the learning curve, is somewhat valid, but for most beginners it forces them to think and remember what they were actually attempting to create in a more clear and concise manner. Having to decide that you're creating a function that calculates a set of areas based on radii ensures that you don't bastardize the function to do something else in a convoluted manner. This is a core programming task of breaking down the problem into smaller well defined pieces that can do one thing well and not 10 things badly. Not learning this results in sloppy and horrible code. The extra time it forces on the beginner always pays off in the future (even when it's a real pain at the time).

It's like driving a car: If you aren't taught by someone that is very stringent in how you do things, you end up being a menace on the road and potentially kill other people because of sloppyness/uncaring.

(Forgot to mention: Great articles, they should trigger some interesting discussions in many developer groups)