Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

The JavaScript Hater's Guide to the NetBeans JavaScript Editor : Page 2

Writing and debugging JavaScript can be painful, but if you develop web applications, chances are that you'll be doing more and more of it. If this sounds like you, the latest version of NetBeans could be just what the doctor ordered.


advertisement
Java-Like Syntax Checks
The editor itself will feel familiar to Java developers. As in most modern Java editors, you also get code folding, which allows you to "fold" away functions that you aren't interested in, and focus on the ones on which you need to concentrate.

The new JavaScript editor can also save you typing. For example, if you type an opening quote or bracket of any kind, the closing token will be automatically inserted for you. And you can ask NetBeans to format your code for you, just as you would do in a Java class, using the “format” menu option in the contextual menu. These are small touches, but they do contribute to making the developer experience more pleasant and fluid.

But more significantly, the JavaScript editor checks your code for syntax errors in real time, just like the Java editor. Of course, by definition, syntax errors are a bit more elusive in JavaScript, but they still happen. And NetBeans treats them as first class errors, displaying them in the code, the margin, and the task list, just like a Java syntax error (see Figure 2).



Click to enlarge

Figure 2. The NetBeans JavaScript Editor Checks for Syntax Errors in Real Time:
Syntax errors are a bit more elusive in JavaScript, but they still happen.

Code Checks
As I mentioned previously, it is terribly easy to make silly mistakes in JavaScript. If you misspell a variable, your code will still run, but it may behave unexpectedly. If you use an assignment operator (x=y) instead of a proper equality test (x==y), for example, you may be none the wiser until your code fails to behave as expected in production. The problem is many of these issues are perfectly valid JavaScript. You really need some sort of static analysis tool, like Checkstyle or PMD for Java, to identify potential problems. In fact, NetBeans 6.1 provides exactly that!

The NetBeans 6.1 JavaScript editor automatically checks your code for code-quality issues of this type (see Figure 3). It will detect several categories of potential error, including reassigned parameters, variables that hide function arguments, and assignments in conditions. These issues appear like warnings in your Java code, and appear both in the margins for the source code window and in the task list.

This static analysis of JavaScript is still a relatively young concept. The number of issues is relatively limited, and nothing compared to the hundreds of issues handled by tools such as Checkstyle or PMD, or even those raised directly by modern IDEs for Java code. Nevertheless, the checks that are provided are useful, and this feature is certainly promising.


Figure 3. JavaScript Code Quality Issues Raised by NetBeans: The NetBeans 6.1 JavaScript editor automatically checks your code for code-quality issues.
 
Figure 4. Quick Fixes to JavaScript Coding Issues: NetBeans also proposes a number of "quick fixes" that let you apply simple fixes to simple problems.

NetBeans also proposes, via the "Source->Fix Code" menu, a number of "quick fixes" that let you apply simple fixes to simple problems, such as replacing "if (x=y)" with "if (x==y)" (see Figure 3). These very convenient features are actually useful around 80 percent of the time. One additional feature that is lacking, however, is the ability to access this functionality directly by clicking or right-clicking on the issue.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap