I've recently poured a couple of hours into JavaScript because I wanted to benefit from the massive userbase. Doing that I have noticed a pattern that most people attribute to dynamic languages. You get things working really quickly, but once your code reaches a certain size you waste much time with type, spelling and refactoring errors in general. Errors a compiler would normally spare me from. And not have me looking for errors in the logic when I just made typo in another module.
Considering the incredible following JavaScript and other dynamically typed languages have I am lead to believe that there's something wrong with my approach. Or is this just the price you have to pay?
To put it more concisely:
- How do you approach a JavaScript (or any other dynamic language for that matter) project with ~2000 LOC?
- Are there tools to prevent me from making those mistakes? I have tried flow by Facebook and JSHint which somewhat help, but don't catch typos.
analyzeDependencies
once, it will suggest it afteranaly
. Also, selecting one instance of the word will select other instances, but not misspellings. – Katana314 May 09 '16 at 13:59===
is your friend. if you are new to javascript don't ever ever ever use==
. And don't always assume that your variable has what you think it has, the web is a way different environment then any other and has some... unique timing qualities all it's own, so tend towards more checks then less. As for typos... get a friend, *really*, get a friend. I once spent 2 hours looking for an error, gave up, asked my buddy to take a look at it while I took a walk, came back he said he fixed it, I had in one place writtenfuncion
instead offunction
. – Ryan May 09 '16 at 22:32"use strict";
. – OrangeDog May 10 '16 at 06:50var a = { b:5 }; console.log(a.a);
. I am sure there are some use cases, but I think most people would like to get a warning when they are referencing the function rather than some field of the function. – TomTom May 10 '16 at 07:51a.b
¯_(ツ)_/¯ – OrangeDog May 10 '16 at 09:23var _myfunction
to hold the return value of a function namedmyfunction
for example. That introduces the danger of leaving off the underscore prefix but that's programming. Single-character syntax errors are the most common there are -- and usually the easiest to find and fix. – DocSalvager May 12 '16 at 19:27