JavaScript considered harmful?

Martin got a little frustrated trying to debug a JavaScript/ActiveX project, and was reminded of Douglas Crockford's book "JavaScript: The Good Parts" and about JSLint

Back in August, I complained about all the bad JavaScript running rampant on the Web. For the past week, I've been knee-deep in a moderately complicated AJAX project, and I suddenly have a lot more sympathy for programmers who write bad JavaScript.

This particular project uses an ActiveX control, so it's limited to Internet Explorer. The good part about that is that I don't have to test on Firefox, Opera, Safari, and Chrome; the bad part is that I do have to test on IE 6 (ugh!), IE 7, IE 8, Windows Vista, and Windows XP.

One of the programmers who worked on this project earlier set up a framework that takes care of running sequences of functions, displaying progress, trapping and logging errors, and posting results back to the server; the AJAX functionality uses jQuery and JSON. I thought the framework was a great idea until I discovered that I couldn't debug my JavaScript the way I expected; after I bitched and moaned about it, he pointed me at the try/catch statement hidden deep in the twisty little passages, all different.

Once I disabled the try/catch statement on the staging server, I found that the new script debugger built into IE 8 worked nicely for finding the errors in my JavaScript and was quite convenient to fire up. I also found that no matter what I did, I couldn't debug the ActiveX control and the JavaScript at the same time. The Visual Studio 2008 debugger can debug either native code or script, but not both at once. There also seems to be a prohibition against attaching two debuggers to the same process.

The JavaScript problems I had reminded me about Douglas Crockford's book JavaScript: The Good Parts (O'Reilly, 2008, 170pp., ISBN 10: 0-596-51774-2 ). As Crockford says, most programming languages contain good and bad parts, but JavaScript has more than its share of the bad. Amen to that.

Crockford recommends using a subset of JavaScript that he considers "The Good Parts", and offers JSLint, an online JavaScript verifier. If you click on the "Good Parts" button at the bottom of the JSLint page, paste your code into the text area at the top of the page, and click on a JSLint button, it'll check your code against Crockford's standards.

"WARNING: JSLint may hurt your feelings."

From CIO: 8 Free Online Courses to Grow Your Tech Skills