Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've been working on a medium sized web application that makes very heavy use of javascript. I tend to introduce common errors per 10 lines of code with either an unknown variable name or function name from another module\namespace or forgetting a return and other common errors.

I'm noticing I'm getting quite a lot of feedback in fixing these errors as a side effect of my qunit testing. Is unit testing a typical way to make up for a compiler in dynamic languages?

share|improve this question
    
Yes. Your experience demonstrates this. Why do you ask? What more would you like to know? –  S.Lott Feb 20 '12 at 19:09
    
I guess I'm curious as to what people use to make up for the lack of a compiler. –  Peter Smith Feb 20 '12 at 19:12
1  
I use jslint to do that kind of testing. Of course there are compiled dynamically typed languages –  Zachary K Feb 20 '12 at 19:15
2  
Most dynamic languages are compiled. The compilers just don't know as much about the code, and hence give less useful warnings. But in theory, you could run e.g. the Python bytecode compiler on every file and get at least the syntax errors. But since the unit tests are equally easy or easier to kick off and are more comprehensive, nobody bothers. –  delnan Feb 20 '12 at 19:26
1  
I'm a bit confused by your question. In what way, exactly, does JavaScript "lack a compiler"? Every single modern JavaScript implementation has at least one, possibly multiple compilers. In particular, all of the JavaScript engines that are currently shipping as part of the major browsers have compilers. And most other dynamic languages have compilers as well. I really can't think of a single dynamic language which doesn't have a compiler. –  Jörg W Mittag Feb 21 '12 at 5:08
show 1 more comment

2 Answers 2

up vote 6 down vote accepted

First of all I would run JSLint over your code religiously. you should be able to get your editor or IDE to do it for you, use Flymake mode in Emacs. That will catch things like typos when you miss type a variable name.

Having good tests will also of course help. I have used qUnit to write tests in Javascript and have been pretty happy with it. Jasmine also is supposed to be pretty good.

As an aside this has to do with dynamic typing not a lack of a compiler, there are a number of languages that are compiled but are still weekly typed (Scheme and Erlang come to mind)

share|improve this answer
add comment

Firebug and Chrome Developer Tools are more than sufficient for simple stuff like this. Just watch the console.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.