Got more questions? Find advice on: SQL | XML | Regular Expressions | Windows
in Search
Welcome to AspAdvice Sign in | Join | Help

C# Nuggets

The trouble with dynamic languages

Javascript is a dynamic language. And that's a problem. On the one hand it allows you virtually unlimited ability to play with data structures and mold them to your own design. On the other, it presents the virtually insurmountable problem of testability.

You see, a dynamic language delays the checks which are performed by a static language during compilation until runtime. So you have no idea whether your code is correct until it is executed. The usual answer to this is to write unit tests. But the people who say this tend to gloss over the difficulty of getting 100% unit test coverage. 70% coverage is usually considered a very high test rate. And then there's the difficulty of getting the coverage metrics themselves. At the time of writing, there is only one Javascript/browser code coverage tool around. Hopefully all the hype surrounding AJAX will encourage more of these tools to be written.

One tool that is available now is JavascriptLint. Lint was the tool you may have used many years ago to statically analyze your C source code for common programming errors not picked up by the compiler. So JavascriptLint does the same but for Javascript. It's based on SpiderMonkey, the C-based Javascript engine in Firefox. So you can be sure it's rock solid with zero false positives. It's a fantastic tool to help AJAX programming as it seamlessly integrates into your favorite IDE as an external tool. Some of the errors it picks up on are:

Some of these are only available with the tool in Option Explicit mode. Even if it doesn't spot outright bugs in your code, the checks for type coercion and missing semicolons are performance bugs in your code.

The benefits of JavascriptLint are so conclusive it gets run over my code several times per day.

 

Sponsor
Published Monday, January 22, 2007 7:51 PM by rbirkby
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Leave a Comment

(required) 
(optional)
(required) 
Enter the code you see below

Submit