JavaScript Everywhere

type=”html”>

[New approach to build nextGen enterprise applications]

Javascript is available in web world for a while and has become one of the most popular, known, understood and also hated language available. There are many reason for ‘Why is Javascript hated’, and there are literatures about how it turned to a vamp, while others tries to see the good part of it.
This article is not about cursing this multifaceted language, but here we will try to explore more possibilities with this language. These days community has expanded this language to everywhere from client-side to server-side. Javascript frameworks are today available in different flavors to meet our different use cases. JavaScript is all set to rock in the arena of next generation enterprise applications.
Under “javascript everywhere” banner the javascript based enterprise application development framework needs lots of maturity to withstand the needs. In this article further we shall be discussing the ongoing standardization of javascript frameworks backed with architectural pattern implementation. Also, we shall be looking in depth on dependency management and javascript loading solutions. Community today is seriously looking at test driven development & design and we shall explore what has been done new in javascript world in this arena.


Pattern Oriented JavaScript Framework

Rebecca Murphy’s article on ‘Jquery & Large Application’ is an excellent write up which details on problems associated with Jquery when adapted for enterprise level applications. By the way it is not just limited to Jquery, but it is a common problem with most of the javascript frameworks available today. JavaScript frameworks which were meant for an older web now no longer can with stand with the requirements of next generation web application. With more powerful browsers, today’s web applications rely intensively on client side and thereby a big piece of code is now migrated to javascript. Today’s applications are now responsible for managing user interaction, state management, data management, web flow and templating all at client side. With such complexities and no framework support, managing piles of javascript would have been a nightmare for a developer.
Today’s javascript frameworks are now backed by architectural patterns which were only known for server side components. Community is striving to build frameworks with which the enterprise application code is more organized and manageable. Frameworks are now developed on top of MV* (MVC, MVP, MVVM) architecture patterns. We today have literature which details on implementing core[1] & enterprise level patterns[2] for javascripts.
Below is comparison matrix which details different pattern available with MV* based JavaScript frameworks.


Framework
UI Bindings
Composed Views
Web Presentation Layer
Integration with others
Backbone.js
No
No
Yes
Yes
SproutCore 1.x
Yes
Yes
No
No
Sammy.js
No
No
Yes
Yes
Spine.js
No
No
Yes
Yes
Cappuccino
Yes
Yes
No
No
Knockout.js
Yes
No
Yes
Yes
Javascript MVC
No
Yes
Yes
Yes
GWT
No
Yes
No
No
Google Closure
No
Yes
Yes
No
Ember.js
Yes
Yes
Yes
Yes
Angular.js
Yes
No
Yes
Yes
Batman.js
Yes
No
Yes
Yes
Note: Credits to Gordon L. Hempton for his research.


Dependency Management & JavaScript Loading

While writing enterprise grade web applications, we land up writing complex code and with time, as application size expands our problem gets worse. With complexity it becomes harder to assemble the code and thereby developer tends to write modular code for understandability and ease of maintenance. And hence the code is broken down into modules which reside under discrete JS files. This may lead to deployment challenges, wherein we wish to minimize HTTP calls for latency optimization.
Today JavaScript community is aware and active for the solution of above problem. There are frameworks which are built to get the above problems solved. Objectives of these tools are to provide dynamic loading of JavaScripts using sort of include/import/requires syntax which are common in today programming language. Also these tools targets resolving nested dependencies between scripts. Of course all these features shall not sacrifice deployment and hence are backed by optimization tools which help in deployment.
Below matrix compares capabilities of such available frameworks:



Framework
Priority based loading
Callback support on loading events
Restrict duplicate JS execution
Dependency management
Web worker support
Cross domain scripts
LabJS
No
Yes
Yes
Yes
-
Yes
HeadJS
No
Yes
Yes
Yes
-
Yes
RequireJS
Yes
Yes
Yes
Yes
Yes
Yes
YepNope
No
Yes
Yes
Yes
-
Yes
BootStrap
No
Yes
-
Yes
-
Yes


JavaScript Testing

An evolutionary approach to development is TDD, Test-driven development which combines test-first development where one write a test before one writes production code to fulfill that test and refactoring. With more and more features coming in javascript plate, it becomes a must to evolve javascript unit testing tools. Cristian Johanson has documented it all on whys and hows around this topic in his book.
Another challenges faced by web applications is the support of web browsers with different versions. This challenge is inherited from the lack of testing the javascript code living in the presentation tier. Without unit testing this code, organizations may pay for repeated testing of web applications after upgrading or supporting new browsers.
Community has also designed specifications for standardizing the javascript unit testing tools.
Below are the different javascript test frameworks available:



Test Framework
Description
JSTestDriver
JsTestDriver aims to help javascript developers use ‘test driven design’ practices and aims to make writing unit tests as easy as what already exists today for java with JUnit.
QUnit
QUnit is a powerful, easy-to-use JavaScript unit test suite. It’s used by the jQuery, jQuery UI and jQuery Mobile projects and is capable of testing any generic JavaScript code
BusterJS
Buster.JS is a JavaScript test framework for node and browsers.
TestSwarm
TestSwarm provides distributed continuous integration testing for JavaScript.
JSUnit
RhinoUnit
FuncUnit
Automated & functional testing.

Client-side Templating

Template engines is always been a server-side technology and migration of this to client side is relative new. There is definitely a shift going on where logic is moved away from the server to the client side, more and more frameworks are gaining traction as this trend goes on, helping us in crafting maintainable code. The basic idea behind client side templating is to offload the server from rendering the template.
Below is a comparison matrix produced by Veena Basavaraj which compares different templating javascript framework.

“The UTurn” – Server side JavaScript (SSJS)

An established pattern of web development is to use a programming language for interactivity in the browser (via. JavaScript) and another for server-side request processing (via. PHP, JSP, ASP, Java, Python, Ruby). However we’re now seeing the rise of JavaScript as a sort of universal web language encompassing the server side too. JavaScript is a “complete” language: one can use it in many contexts and achieve everything what can be achieved with any other language. With SSJS one can run JavaScript code in the backend, outside a browser, and thus can support HTTP processing and hence can act as server side language as well.
Idea behind the SSJS is using high performance javascript engines designed for different web browsers. E.g. NodeJS sits on top of V8, Google’s VM for javascript processing. SSJS has been evolving as a general purpose programming platform, but its core strength and expertise lies in doing networking correctly. This can be viewed as javascript bundled in console with set of APIs on top of it. These APIs provided are not just limited to normal programming but extend to assist programming web servers.
Serverside javascript typically designed to take care of event driven model. In a typical webserver, every client request spawns off a new thread. So server spawns large number of threads for requests, even if some threads are just sitting idle waiting for some task to complete. With event driven programming, one can register events and once the results return from the database, event calls are made. So idle time is less and thread footprint is minimal. By the way this shall not be considered as an alternative to asynchronous programming, which has its own advantages.
Below is the list of different server side javascript frameworks.



Framework
JavaScript Engine
Server Type
Description
CouchDB
SpiderMonkey
HTTP
JavaScript in CouchDB is use to write map/reduce queries. It’s also used for document validation & update handling
Google Apps Script
Rhino
Cloud (PAAS)
GAE
Google Apps Script is a JavaScript cloud scripting language that provides easy ways to automate tasks across Google products and third party services
NodeJS
Chrome V8
Standalone
Platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. It uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
Wakanda
SquirrelFish
HTTP
Wakanda Server’s ease of use and high performance are all tied to its implementation of JavaScript (based on WebKit’s Squirrelfish Extreme just-in-time compiler) and the datastore class paradigm. In addition to accessing data from HTML5 widgets on the front end, all of the servers data and logic is available directly to you via JavaScript using standards-based APIs

Conclusion

 ‘JavaScriptEverywhere’ has added a new thinking hat; applications are now designed keepingit principle in mind. With SSJS platforms which are built over JavaScriptruntime can be used for easily building fast, scalable network based applications.It uses an event-driven, non-blocking I/O model that makes the serverlightweight and efficient, perfect for data-intensive real-time applicationsthat run across distributed devices. Today many enterprises like LinkedIn,Ebay, Yahoo and many others srely on such frameworks.

With adaption of best practices and patterns in client side frameworks, managing code is now no more a nightmare. Javascript dependencies can be easily managed and optimally loaded in the browser more efficiently and quickly. Data interchange format of course is none other than JSON which fits in this architecture.
Today, NoSQL databases are a game-changer on the back-end and it brings a new paradigm to web development. When we put them with the new architecture, we have a well-integrated engine all the way down. All of a sudden, Javascript becomes a mainstream language and can be used for both front- and back-end. The entire stack speaks one language and integrates like a charm.

References

http://bitovi.com/blog/2010/08/why-jquery-needs-javascriptmvc.html
http://rmurphey.com/blog/2010/08/09/on-jquery-large-applications/
http://addyosmani.com/blog/understanding-mvc-and-mvp-for-javascript-and-backbone-developers/
http://addyosmani.com/resources/essentialjsdesignpatterns/book/
http://addyosmani.com/largescalejavascript/
http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed/
http://stackoverflow.com/questions/300855/looking-for-a-better-javascript-unit-test-tool
http://engineering.linkedin.com/frontend/client-side-templating-throwdown-mustache-handlebars-dustjs-and-more
http://www.nodebeginner.org/#javascript-and-nodejs

View the Original article

One thought on “JavaScript Everywhere

  1. Pingback: yhe098yfu8hf8yuh809

Leave a Reply