Monday, May 12, 2014

State of the Stack: What Javascript Libraries Do You Use?

Every now and then I take a moment to reflect on the state-of-the-art and make sure I'm not heading the way of the dinosaurs. Every five years or so, the Internet seems to head in another direction (or at least starts to shift). Technologies and techniques get old fast and staying on top of the latest trends is important to remain relevant. Building your client stack probably starts with the selection of a MV* like library. What you choose will impact all aspects of your project. InfoQ has built a survey of adoption of various MVC libraries. You have to vote to see the results but it probably should not come as too big a surprise that Angular, Backbone, and Knockout are at the top of the list.

Interested in how that compares to another source, I turned to GitHub to look at popularity. The number of watches, stars, and forks is a pretty good indicator of relative adoption:



The "related" graph depicts how many results you get on GitHub when you search for one of these libraries. Its a reasonable indicator of the supporting ecosystem that has evolved around the library. Why is this important? By themselves, these libraries are not complete frameworks that allow you to build web apps. They do help solve the problem of separating data and logic from the DOM and establishing good design patterns. However, depending on your application, you'll need a lot more than these solutions to create the desired user experience. I've attempted to generalize the basic components you'll probably consider when building your application:



Each of the top three MVC libraries address parts of these areas and provide meaningful support to extend or integrate other solutions as necessary. The supporting community around these tools becomes important as you try to find existing solutions to meet your needs. The less you have to write and test the better. If it already exists and, is in reasonably high use, then you can feel comfortable that it will work and you can focus on solving problems unique to your application.

Today, I primarily use Backbone as my MVC. Its strength lies on the data side with a focus on abstracting the acquisition and persistence of data to the server. I typically swap out Underscore in favor of Lodash and drop in MomentJS to make date manipulation a breeze. On the UI side of things, I start with Bootstrap and only use the interaction and autocomplete widgets in jQuery UI. RequireJS takes care of managing modularization and dependency management. Everything else is pulled from one of the ecosystems surrounding those main libraries and adapted to play well with each other. Most of the glue code I have written is related to streamlining the two-way bindings with form controls and the data sources. Its probably the greatest weakness of Backbone, and although the community has some solutions, it still required some work to fill the gap and create something that worked within the context of applications I need to build.

These MVC libraries are all entering their fourth year of existence. At this point, we can probably call them mature and reasonably stable. The question is, if technology keeps changing at its historical pace, how relevant are these libraries in building the future of the web? What are the latest innovations in building better technologies for developers to enable writing leaner, more efficient code that creates a rich user experience that performs well across both desktop and mobile devices? We'll always discover better ways to do the same thing and be faced with finding new solutions as technology changes. I'd expect these established libraries to be capable of adapting to these changes for some time to come. Maybe in another 10 years we'll look back and say that these solutions are out dated and no longer represent the cutting edge, defacto standard developers turn to when building applications.