The primary aim of SPA JS is to keep development simple and eradicate repetitions. It also follows the crucial principle, YAGNI (You Ain’t Gonna Need It), which states that you should “Always implement things only when you need them but never when you just think that you may need them.” For example, in open source software, contributors may develop different modules by assuming that you may need them. However, these modules may not be useful at all.
Why SPA JS?
Many of you may be familiar with Angular, React and the Vue.js framework but very few may be aware about frameworks like Knockout, Ember and Backbone. It’s not that Angular, React, etc, are really game changers. We already had the concept of building a single page application using these frameworks. So, let us examine the problem with Angular, React or Vue.js, as well as other programming options.
Problem 1: The question is why do we have different frameworks? This is because developers try to build some applications on one of these frameworks, but the latter do not solve their particular problem in the way they want to. So, developers try to create their own frameworks that solve their individual problem, but this leads to a lot of frameworks.
So, companies and developers are facing the issue of how to create a perfect bridge between the frontend and backend. Recently, the term ‘full-stack developer’ has emerged, describing those who know all the backend development, including databases. However, the full-stack developer doesn’t know all the developments related to every platform or framework, and that’s the current problem being faced.
The first law of software quality is e=mc² (errors=(more code)²). This implies that the more the code, the more the errors. Just take an example of Angular or React. The seed project that we download with one package json, with one or two files like index.html, does not allow us to start our project. We now need to do a npm install, which downloads approximately 120MB of code. And all this needs to be done even if you need to just demonstrate ‘Hello World’.
We think that we are writing less code but, unfortunately, we are not — it is more likely we are writing less code as someone else has already written it, and we have installed it along with our seed project.
Steve Jobs explained the problem like this, “The way you get programmer productivity is not by increasing the lines of code per programming per day. That doesn’t work. The way you get programmer productivity is by eliminating the lines of code that you have to write. The goal here is to eliminate 80 per cent of the code that you have to write for your app. That’s the goal. I’ve seen a lot of demos that try to take it all the way back into the algorithmic part of the code base, and none of them have ever been any good.” So, the less the code, the fewer the errors, and the higher the productivity.
Let us get back to SPA JS
To get started, visit https://spa.js.org/. The site has all that is needed to learn and use SPA JS. Also, it is on a pure MVC framework that provides flexibility to developers.
The structure is well organised, which helps to reduce the code complexity. Even when the developers try to mix up the code, SPA JS will not allow it. It has a clear view that is separated with three layers — one layer with pure HTML content, the second with all the controls, and the data layer (which is entirely API driven) that helps to build the perfect bridge. One of the significant problems with Angular.js is that the features keep on updating periodically, and it is challenging to teach developers these features and frameworks. SPA JS has tried to address this issue. The site also has all the guides, so developers don’t need to Google for a solution.
By: Kumar P.
The author is a consulting engineer and chief frontend architect at Unisys. This article is based on the talk he presented during Open Source India 2019.
Disclaimer: The views presented in the article are personal and do not represent the views of the organisation the author works for.