Monday, October 25, 2021

WHY REACT JS IS BETTER THAN ANGULAR OR VUE JS?

 It’s common knowledge that web pages are primarily built with HTML, CSS, and JavaScript programming languages (the three fundamental building blocks of the web). Specifically, HTML creates elements on web pages, such as menus, texts, and boxes. While CSS is utilised to style, design, and place those elements on web pages. And lastly, JavaScript, which facilitates the interaction with, and manipulation of these elements. The theme of our discussion will revolve around JavaScript; in particular React.Js and its superiority over Angular and Vue.Js.

In summary, React JS is better than Angular or Vue JS because of its superior Virtual DOM capabilities, its robust community support, rich documentation, its light-weight attributes, manageable learning curve, and its flexibility to allow mobile functionality with React Native’s.

JavaScript: The Glue Language

To set a precedence for our case justifying React’s dominance, we’ll recap some basics. JavaScript has often been identified as a glue language, used for assembly of other components. Out of the three web building blocks, HTML and CSS are less complex (though mainly used for static design purposes). However, for developers who create dynamic web content, JavaScript is a priority, which indicates why it’s much larger and more complicated than its contemporaries. Essentially, becoming the de facto standard employed on most web pages.

Consequently, over the last decade, multiple front-end frameworks have been engineered on top of JavaScript to ease the development and maintenance of websites. Resultantly, as of 2020, the most popular of these front-end JavaScript frameworks were React and Vue, then Angular.  

Since we have briefly established that JavaScript and JavaScript-based frameworks and libraries are critical tools for web development. So, to set the context for our blog, let’s backtrack briefly and outline the history and development of JavaScript.

The History of Web Technologies & Browsers

The first web browser was developed and released in December 1990 with Tim Berners-Lee serving as the lead developer. He simultaneously developed and released the Hypertext Transfer Protocol (HTTP), the application protocol for the World Wide Web for indexing and navigation of web sites.

Later, the inaugural graphical web browser, Mosaic, was released in 1993. Similarly, in the same year, HTML was developed. This was a few years before JavaScript was created, while CSS was released in 1996, one year after JavaScript. These three languages later famously formed a technology stack dubbed “the triad of technologies that Web developers must learn”.

The Development of JavaScript

One of the famous follow-ups to the Mosaic browser was the Netscape Navigator browser, released in 1994. In 1995, the developers of the then-popular Netscape, hired Brendan Elch, a programmer, to create a new dynamic scripting language for web pages and client-side manipulation of data.

In response to the market, Netscape saw the need to create dynamic websites instead of being limited to HTML. Unfortunately, most early websites employed only HTML, and thus were computationally inefficient.  So, Netscape was compelled to devise a simple web scripting language targeted for DOM (document object model) manipulation. The project was consequently inspired by the functionality and syntax of Java  though they’re fundamentally different despite a minor syntactic resemblance.

Officially released in March 1996, JavaScript eventually enabled new functionality on web pages that HTML alone could not. For example, responding to user input, showing pop-up windows and changing colors of elements. Netscape was later acquired by America Online (AOL) who also owned Mozilla, which contributed to JavaScript’s exponential growth as an internet standard.

The Emergence of XML, AJAX, and the Single Page Applications

Later in the early 2000s, web users were frustrated with slow server responses and long data transmission times. These were further aggravated by the low-speed Internet connections that marked the era. The led to the development of the AJAX technology stack (Asynchronous XML and JavaScript)

In this regard, XML is a markup language similar to HTML, though used for data representation instead of content display. XML became relevant within JavaScript with the creation of the AJAX stack.

Often described as a collection of several technologies, bundled together as a whole, AJAX comprises of XHTML, CSS, DOM, XML, XLSTXML HttpRequest, and JavaScript. And within AJAX, JavaScript binds all the other tools together. Consequently, AJAX provided a way to update parts of an HTML page without downloading its entire content.

Single Page Applications

Generally, all of the JavaScript frameworks adopt single page application principles. In practice, a Single Page Application (SPA) is an application comprised of individual components, that are loaded into memory upon a first-page visit, and can then be replaced or updated independently, so the entire webpage doesn’t have to be reloaded on every user action.

Furthermore, with SPAs, components can be reused, and thus the amount of code needed is dramatically reduced. The first single-page application was implemented in 2002, with JavaScript intended as one of the target languages for implementation. The success of single-page applications was mainly thanks to the preceding AJAX technology and its precedence in server communication.

The JavaScript-HTML Relationship

HTML can work either as a complement to JavaScript, as with jQuery; or as integrated, HTML-like syntax that is compiled into HTML elements. An instance of this is the JSX syntax, recommended for use when developing with React. It is neither pure JavaScript nor HTML, but an amalgamation of them both. So, fundamentally, integrating the basic element creation and structural functionality of HTML with the dynamic capabilities of JavaScript.

CSS-HTML Relationship              

CSS is commonly used in combination with JavaScript. A traditional example format, is to implement CSS properties in separate .css files. The other format is to integrate CSS into the JavaScript frameworks themselves, through specialized libraries such as CSS-in-JS and styled-components. Such libraries enable developers to write JavaScript code that styles visual elements with CSS-like syntax which is then usually compiled into pure CSS in the browser.

The Emergence of a Server-side Implementation of JavaScript

Eventually, 2009 came with the release of Node.js, a server-side implementation of JavaScript. Node.js extended the JavaScript domain to the back-end, enabling JavaScript to become a full-stack language.

Node.js is currently the most employed JavaScript runtime environment, used for executing JavaScript code outside of the web browser environment. Utilised for server-side functionality, the creators of Node.js aimed to develop a more efficient alternative to the then-popular Apache HTTP Server (often used with PHP). Node.js was created using Google’s V8 JavaScript engine, which itself was built using C++.

Front-end JavaScript Frameworks

Since we’ve set the foundation, we can now lay the bricks and delve into the reasons for our React.js inclination.

Frameworks Versus Libraries

A common argument is what qualifies as a library when talking about this JavaScript trio. Ironically, React is occasionally referred to as a library, and at other times as a framework. However, for clarity and consistency, it’s often useful to separate frameworks from libraries.

Particularly, a library is a passive collection of non-volatile resources where developers are given control over how to use the resources. They are typically very simple and only perform one certain task, thus can be classified as tools.

While frameworks are designed to be less passive and force developers to do things in a certain way by availing a skeleton for development purposes and enforcing a control flow. For example, a developer is provided with a defined way to develop and set up a whole web application. While a web application library does not, instead providing simpler sub-domain operations, like network requests or styling operations.

Though Vue and Angular are technically considered frameworks, there is still some disagreement regarding whether React is a framework or a library. While the original developers of React refer to it as a library, it’s still more commonly used as a framework.

Why React is the Dominant Alternative!

In hindsight, React was developed as a JavaScript port of XHP (a PHP library created by Facebook). Generally, XHP was a modification of PHP that allowed for custom component creation, and aimed to prevent malicious user attacks. Later out of this JavaScript porting project grew JSX (JavaScript XML), which became a common standard language for React.

All things considered, React has a narrower scope than its peers, only rendering the application user interface. However, it maintains the benefit of a lightweight structure, and hence is less costly to learn and use. That being said, it can still be considered a framework, as it is used for the same purpose as Vue and Angular.

Superior Virtual DOM Capabilities.

React was the first framework to optimize its functionality according to the DOM. This was a contributing factor to its success since DOM manipulation is quite costly in terms of computing resources used. Specifically, React was designed to perform as little DOM manipulation as possible by employing intuitive state management and the virtual DOM to control this manipulation.

This exploitation of the virtual DOM makes React update faster, at the expense of being more memory intensive. And in order to execute fast updates to the browser DOM, react maintains a copy of the virtual DOM tree in memory, which consumes additional memory. Consequently, React’s popularity gave birth to numerous spinoff libraries such as React Native for mobile development.

One-Way Data Flow

In React, the data is meant to flow downwards, and is referred to as one-way data flow. While Angular and Vue’s two-way data binding makes the code prettier and simpler, React compensates in superior manageability and performance. A notable advantage in our argument.

Why React Is Better Than Angular

Let’s do a case by case comparison for more context, shall we? Intended for larger application development, Angular is a more full-featured JavaScript framework, in terms of programming features and file size.

However, in comparison to React, Angular has negative bloatedness, complexity and heavy style of development traits. It is recommended for smaller development projects and cited as having a steep learning curve. To exacerbate things, AngularJS is no longer under active development.

Angular is built entirely in TypeScript and requires lots of code which makes it a bit complicated. On the contrary, React is quite “simple” and its original orientation is focused on controlling and manipulating the view. Essentially, it allows the developer to select exactly what they need, but also it avails the ability to use a large number of third-party packages. So, consequently, React doesn’t include a lot of overhead in comparison to Angular.

Why React is Better than Vue

Vue.js was created by Google employee Evan You. Evan was inspired by AngularJS, but wanted to create a more streamlined, improved version of it. Despite its lightweight attributes, great performance and nice programming style, Vue’s negative aspect is its clumsiness.This where React’s superiority shows off.

For instance, there is no clear best practice in Vue.js in contrast to React, which may make it difficult for major applications to be maintained. However, the best practices for React are found in the community. For example, creating a viable workflow is enabled through the official create-react-app package. Due to the above points, React suitably provides the ability to write and maintain a lot of complex code.

ES6 Syntax

Furthermore, developers can utilise ES6 syntax as well with Vue, however, React is more optimally-designed than Vue in this regard. While Vue currently offers TypeScript support, its support is not well polished like React using CRA (Create React App) with TS support in a single command. Additionally, with Vue, we still require some third-party packages with custom decorators and features to create a true, complete TypeScript application. And unfortunately, the official documentation does not provide all the information required to get started. Another React advantage!

As we cement our argument, let’s further breakdown the discussion using clearer certain benchmarks.

1. Framework Size

While the size of a framework’s minified package in the npm registry is unlikely to discourage or encourage any developer from selecting the framework, it can still help our argument. Angular is notably quite a bit larger than the rest (187.6 kB) while React is 6.4 kB and Vue falls somewhere in between, at 63.5 kB.

Generally, the package size comparison shows that Angular supports and contains a larger breadth of functionality, while React is designed for more streamlined development. React’s nature thus gives the developer fewer choices to improve efficiency, which is beneficial handy for smaller projects.

Furthermore, Angular’s complicated structure leads to a potential risk of poor performance in comparison to React or Vue, especially for memory allocation.

2. Development Experience, Learning Curve, And Availability

Generally speaking, TypeScript is not in itself much harder or easier to learn than JavaScript. However, it is not as widely used and contains fewer libraries and overall documentation than JavaScript. These factors, compounded with the differences in syntax and the time it takes to get used to coding in a slightly different variation of JavaScript, provide a slight advantage to React over Angular.

3. The Language-based Situation

Another key point is React and Vue use JavaScript ES6 as their based language. ES6 is the newest JavaScript industry standard from 2015. On the other hand, Angular 1 leverages the JavaScript ES5 which is the previous version while Angular 2 relies on TypeScript.

Though TypeScript enables developers to get rid of traditional JavaScript programming format, it, however, has limited user communities. This means that there is a potential risk that TypeScript might disappear if another new syntactical strict superset of JavaScript appears. On the contrary, JavaScript ES6 will not disappear soon because it is the current industry criterion when developing in JavaScript.

4. Documentation

In all honesty, the availability of documentation is satisfactory for all these frameworks. That said, it’s still noteworthy that the documentation of React is available in the largest number of languages (16). Vue falls behind, with documentation in 8 languages, while the Angular documentation is available in 4 languages. React documentation is coherent and has united theory in delivery for different developers.

Unfortunately, the framework situation of Angular may present some difficulties for a developer in that it is split between AngularJS and Angular 2. Furthermore, the term “Angular” can at times come off as ambiguous as to which framework it refers to in online contexts. Specially when browsing smaller sites and shorter answers.

5.      Community Support

For the most part, React arguably has the largest community support currently among all JavaScript frameworks. This exemplified by the breadth of its discussion forums and chat rooms. Also, users can follow the latest news and participate in the discussion on Facebook and Twitter. 

Svelte Framework (An Honorable Mention)

We thought it wise to mention a relatively new entry into the JavaScript sphere. Developed by Rich Harris and initially released in 2016, Svelte gained massive popularity throughout 2019. It introduced several enhancements in JavaScript such as changes in local state handling.

It’s also worth noting that Svelte has no virtual DOM and converts written code into JavaScript at build time, instead of run time. Essentially, it circumvents converting declarative elements to the real DOM.

Summary

Though Vue has slightly more Github stars, React is still superior with no discernible weaknesses, and better performance strengths. In essence, better performance means lower loading times and increased user satisfaction. Furthermore, for commercial websites, this results in revenue increases as a loading time reduction of a couple of milliseconds can increase user interaction and retention.

Ultimately, the future of the JavaScript framework landscape is difficult to predict. Though as evidence suggests, React is likely to remain the dominant framework for the foreseeable future. However, for developers looking to develop applications utilising a mature, well-supported framework with a great performance and plenty of documentation, React is the superior choice!


No comments:

Post a Comment

Top 5 Generative AI Tools You Need to Know

Introduction In the realm of artificial intelligence (AI) development, the emergence of generative AI tools has ushered in a new er...