Martin Heller
Contributing Writer

JavaScript considered harmful?

analysis
Oct 21, 20082 mins

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

shutterstock 1361674454 JavaScript Hello code in programming text editor
Credit: Bigc Studio / Shutterstock

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.

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.”

Martin Heller

Martin Heller is a contributing writer at InfoWorld. Formerly a web and Windows programming consultant, he developed databases, software, and websites from his office in Andover, Massachusetts, from 1986 to 2010. From 2010 to August of 2012, Martin was vice president of technology and education at Alpha Software. From March 2013 to January 2014, he was chairman of Tubifi, maker of a cloud-based video editor, having previously served as CEO.

Martin is the author or co-author of nearly a dozen PC software packages and half a dozen Web applications. He is also the author of several books on Windows programming. As a consultant, Martin has worked with companies of all sizes to design, develop, improve, and/or debug Windows, web, and database applications, and has performed strategic business consulting for high-tech corporations ranging from tiny to Fortune 100 and from local to multinational.

Martin’s specialties include programming languages C++, Python, C#, JavaScript, and SQL, and databases PostgreSQL, MySQL, Microsoft SQL Server, Oracle Database, Google Cloud Spanner, CockroachDB, MongoDB, Cassandra, and Couchbase. He writes about software development, data management, analytics, AI, and machine learning, contributing technology analyses, explainers, how-to articles, and hands-on reviews of software development tools, data platforms, AI models, machine learning libraries, and much more.

More from this author