3

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?

asked Feb 20, 2012 at 18:48
6
  • Yes. Your experience demonstrates this. Why do you ask? What more would you like to know? Commented Feb 20, 2012 at 19:09
  • I guess I'm curious as to what people use to make up for the lack of a compiler. Commented Feb 20, 2012 at 19:12
  • 1
    I use jslint to do that kind of testing. Of course there are compiled dynamically typed languages Commented Feb 20, 2012 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. Commented Feb 20, 2012 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. Commented Feb 21, 2012 at 5:08

2 Answers 2

6

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)

answered Feb 20, 2012 at 19:14
0

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

answered Jan 16, 2013 at 14:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.