JavaScript Is Eating the World

JavaScript tutorial.

With due apologies to Marc Andreessen, I believe that a very specific type of software is eating the world, namely, JavaScript. There are several trends and technologies that are coalescing at the same time to make Jeff Atwood’s famous “law”—any application that can be written in JavaScript, will eventually be written in JavaScript—more true than ever.

AJAX and Responsive UI: Hard as it is to believe, there was once a time when a Web page meant some static HTML markup, some data bindings (e.g. JSP tags) and a big ol’ Submit button that sent all the form data to the server synchronously while users waited around finding new ways to twiddle their thumbs. We’ve thankfully moved away from that to more responsive UI’s that combine JavaScript, AJAX and DHTML to exchange data with the server asynchronously and deliver vastly better (and faster) user experiences. If you’ve traditionally thought of yourself as a ‘server-side’ developer, you can no longer get away with dropping in a couple of data binding/templating tags into static HTML markup that your creative team sent over. You need to get over your JavaScript phobia (if applicable) and learn to develop responsive, rich UIs. The good news is that there are many great JavaScript libraries like JQuery and  Zepto.js (for basic DOM manipulation) as well as JQuery UI, YUI and  Ext JS (complete UI frameworks) that make this relatively easy to do.

Increasing maturity of JavaScript: Another factor that is contributing to the move to more client-side (i.e. in the browser) processing is the increasing maturity of JavaScript. This may surprise the legion of JavaScript haters out there, but JavaScript is all grown up (well, kinda). With MV* frameworks like Backbone.js, Angular.js, Ember.js (and many others), you can now provide structure and organization to JavaScript-heavy Web apps. There are also some very interesting client-side templates for JavaScript (like mustache, underscore.js,dust,js etc.) that let you render dynamic web pages on the client side (vs having the server return the assembled HTML markup). The next version of JavaScript (aka ‘Harmony’) that is currently making its way through the standards body should also go some ways towards making JavaScript a truly first-class language. And if you’d rather not deal with the, oh let’s just call them ‘eccentricities’, of JavaScript (case in point—can the real ‘this’ please stand up?), there is always CoffeeScript.

Mobile web development: We’re living in a mobile-first world where the number of mobile apps is growing exponentially by the day. Many of these apps are native to the respective mobile platform (i.e. Android or iOS), but a significant percentage are Web applications built using HTML5, CSS3 and yes, JavaScript. A mobile Web application typically employs a “fat-client” architecture whereby a majority of the business logic and view rendering is implemented in JavaScript with the server simply exposing REST/JSON CRUD APIs for the backend data. Modern JavaScript frameworks like JQuery Mobile help ease the development of such mobile-first/only web applications.

There are also some very powerful frameworks like PhoneGap/Cordova, Appcelerator Titanium and Sencha Touch that provide a so-called hybrid approach to developing mobile apps. This hybrid approach combines the advantages of Web development (using standard browser technologies like HTML5, CSS and JavaScript) with some of the benefits of native apps (native binaries, app store listings etc.). Though each of these frameworks differ widely in how them implement a hybrid architecture, the one constant is the use of JavaScript in implementing at least some of the app logic.

Node.js: So far we’ve only discussed why JavaScript is such an indispensable tool for front-end development. However, with the ability to write server-side logic in JavaScript with Node.js, you can now develop entire applications in JavaScript. Yes, server-side JavaScript is not new, but it has gained critical mass with Node.js. The asynchronous, event-loop driven nature of Node.js may not be a good fit for all types of apps, but it’s a very powerful development paradigm with a large and passionate developer community behind it. To be truly successful on the server-side though, JavaScript will need a rich ecosystem of libraries and frameworks that are optimized and designed specifically for a server-side environment (vs accessing/manipulating the DOM). There is progress to report on that front as well with the CommonJS project’s attempt to define a standardized set of APIs to access things like the file system, network etc.

HTML5 and CSS3: Back in the day, developers had to use various proprietary plugins and technologies like ActiveX and Flash to implement rich UI interfaces. With the advent of standards like HTML5 and CSS3, however, you can now develop compelling Web applications that support push notifications (via WebSockets), advanced graphics (via Canvas, WebGL etc), offline access (application cache and client-side storage) and much more without having to resort to proprietary plugins or technologies. JavaScript is the perfect compliment for HTML5/CSS3 web apps and is required to implement many of the advanced features like WebSockets, WebGL etc. JavaScript libraries like Modernizer can also help abstract/mitigate some of the browser compatibility issues that still plague HTML5 and CSS3 development.

Grand Unified Theory

Having outlined my Grand Unified Theory for application development, it is now time for an important caveat. The reasons outlined above for why JavaScript is indispensable for modern application development largely apply to Web and mobile apps. There are any number of applications that don’t fall into either of those categories and the role of JavaScript is minimal in those types of apps (for now).

But love it or hate it, the one thing a modern developer cannot do is ignore JavaScript. It is slowly but surely eating your world.

 

Sandeep Bhanot is a mobile hacker by inclination and a Principal Developer Evangelist at Salesforce.com by trade. In a prior incarnation (he is Indian, after all), he was an Enterprise Architect and SOA Consultant. As a Developer Evangelist at Salesforce.com, he helps spread the gospel of the Cloud and Mobile. He writes 140 characters at a time here and longer pieces here.

Image: Wikipedia

Related