innovating tomorrow's government
« Home
posted on 05.11.2011 posted by Rob Proper

Developing In Javascript

In recent years there has been a surge of interest in Javascript, due to the growing popularity of web applications that use asynchronous-style programming (Ajax) and cross-browser libraries (such as jQuery.) Examples of such applications are Google Maps, Twitter, Gmail, Live.com and Google Suggest. Outside the browser realm there are also some interesting developments, such as the new Javascript engine V8, that started a game of Javascript performance leapfrog amongst the major Javascript engines; node.js, an event-driven I/O framework intended to be used for scalable network programs, such as web servers; and the bundling of the Javascript engine Rhino with Java SE version 6.

Still, Javascript is most often associated with web development. It has become the de-facto HTML scripting language and it certainly is ubiquitous in web development these days.

Frustrations

With just some knowledge of a language from the C-family (such as Java and C#), it is easy to get started with Javascript, even without really knowing much about the language itself. The language is very forgiving of errors. However, the flexibility of the language can mask its true power, and more importantly the differences with C-like languages. It is not uncommon that this leads to frustration and discourages developers, resulting in a characterization of Javascript as “not a real language.”

A lot of frustration also stems from the differences in how the various browsers implement Javascript. These differences are actually not in the language itself, which is implemented fairly consistently across various browsers (and browser versions.) The differences are in the implementation of the DOM API by the various Javascript engines. The Javascript DOM API is the native programming interface that allows developers to interact with the elements of an HTML page, to make the page more dynamic. For example, it allows a web page to process server requests in the background using Javascript, thereby improving the end-user’s experience. There are significant changes between the implementations of this API between the various web browsers. Of course, when doing web development, interacting with the DOM is unavoidable, thus it is understandable that many developers see Javascript as being synonymous to the native DOM API implementation.

Core Language

Javascript has been around for 15 years and shares a C-like syntax with Java, but at a fundamental level it shows greater similarity to a Lisp dialect (Scheme) and a prototype-based language (Self.) Javascript is a relatively small language, but as it turns out, it is a surprisingly powerful and expressive language. The functionality inspired on paradigms of Scheme and Self are significantly different than the programming paradigms typically found in C-like languages.

Just like every other language, Javascript has its quirks (such as semi-colon insertion), and perhaps even more so than other languages. Javascript can definitely throw you a curveball. However just like with any other language, if you understand its core principles, you can harness its power and avoid problems. There are plenty of great resources to be found in helping you to understand the language. I like “Douglas Crockford on Javascript”, but there many others.

Functional Programming

I had already done some Javascript development, adding simple behavior to HTML pages, before I had my Aha!-moment. My earliest professional programming experiences were rooted in functional programming, developing knowledge-base (aka expert) system components using Common Lisp Object System (CLOS). Early on, I learned the benefits of functional programming concepts, such as pure functions (functions without side-effects), high-order functions, closures, and monads. Every programmer should probably have some functional programming experience under their belt to make them a better, more rounded programmer. Once I realized Javascript supports functional programming concepts as well, programming in Javascript became a lot simpler, and more fun. The availability of the functional programming paradigm is what makes Javascript a powerful language.

Cross-Browser

There are many cross-browser Javascript libraries available that can make web development simpler. DOM libraries such as jQuery and Prototype provide a layer of abstraction above the native JavaScript DOM API, in effect hiding the differences between the browser implementations. These libraries make good use of capabilities that Javascript provides, such as Object Detection. It is important to understand these capabilities whether you use a cross-browser library or not. It can help you navigate the cross-browser problems, and make your Javascript code more robust.

Javascript at Aquilent

At Aquilent we do our fair share of Javascript development. For example, Aquilent recently customized the webmail application of the Disaster Information Management Research Center (DIMRC)  radio emergency backup system, which the US National Library of Medicine (NLM) develops for the Bethesda Hospitals Emergency Partnership. This system provides a means of (electronic) communication, in case of an internet blackout, between various locations in the participating hospitals. The system also allows for communication from the hospitals to the world outside the blackout area using radio transmissions. The customization involved extending the webmail application with a chat function that allows for direct communication between the hospitals. This chat function makes extensive use of Javascript and was built on top of the JsJaC library (implementing the XMPP protocol.) Thorough understanding of core Javascript helped us significantly reduce the complexity of this functionality.

In summary, when developing in Javascript, especially web applications, it pays to understand the core principles of Javascript. It can help to avoid many frustrations and help you build powerful features providing excellent functionality to the end-user.

« Home
leave a reply_
*Required **Required but will not be published

Comments are closed.