Enrolled to Infinite Learning

Friday 18 September 2020

Frontend Development Essentials

Oftentimes people ask me on where to start with to become a frontend developer. I generally give them an overview and suggest to befriend Google. But what I figured out lately is that Google apparently overwhelms you with tons of results for each keyword and confuses you more than educating! This post is a broader level roadmap and assistance on the same note. UI development is an ocean, this one is just a drop near the shore. 

Basic Pillars of Frontend Development-

HTML 

Hyper Text Markup Language (HTML) is a markup language that allows you to structure the information that is displayed to the user. Its the An HTML document consists of elements each represented by an HTML tag, such as a heading, a paragraph of text or a text input field. HTML documents can also link to other documents using hyperlinks. Each tag carries its own type of content, has a certain appearance and attached behavior.

CSS

Cascading Style Sheets (CSS) is a styling language used to describe the visual appearance of HTML elements. It can be used to controls aspects like the positioning of an element, its dimensions, text style or colors, or almost any other visual aspect of a website. Styles are defined as a set of rules that can be applied to a single element of a subset of elements on the page.

Preprocessors

Preprocessors extend the capability of CSS to make your CSS code base simpler and maintainable. Various preprocessors like SASS/SCSS, LESS, PostCSS can be leveraged for this purpose.

Javascript

JavaScript (JS) is the most used programming language for developing user interfaces for the web. It allows you to add custom behavior to your websites, such as reacting to user events, loading data from web services and showing or hiding elements on a page. It also allows you to interact with the browser through various APIs. You can use it to both add separate interactive elements to your website or create complex web applications.

Plethora of Tools

PACKAGE MANAGER- NPM

TASK RUNNERS- Webpack, Grunt, Gulp

ONLINE CODING ENVIRONMENTS- StackBlitz, CodePen, JSBin

CODE EDITORS – Atom, Visual Studio Code, Webstorm

FRONT-END ASSETS- Google fonts, FontAwesome, Unsplash

DEVELOPER TOOLS- Chrome Dev Tools, Firefox Page Inspector, Microsoft Edge Developer Tools and Safari Web Inspector

CODE LINTING- ESLint, JSLint, CSS Lint

Modern Frontend Libraries

React  is a user interface development library developed by Facebook. React is based around creating components, such as a button or a side menu, that can render HTML based on input parameters. React components are written using an extension to JavaScript called JSX, that allows you to conveniently combine JavaScript code and HTML. Components can be composed together to create complex UI elements and whole applications. React is not a framework per se, it only provides the view layer, however, its rich ecosystem of tools and libraries.

Angular is another JS framework for developing user interfaces. It is developed by Google, based on typescript, and is component oriented. It provides most of the things you’ll need to build a web application including a CLI tool to bootstrap, develop and build the project as well as libraries to manage forms, data loading, routing, etc.

Vue.js is a framework designed to be modular and incrementally adoptable. You can start using it as a view layer and add additional libraries as you need them.

General Best Practices

Modern Javascript frameworks are evolving quickly to meet the high-end needs of user experience and upgraded development environments. Yet, to leverage them at their maximum potential, one needs to follow a set of standard practices.

1. Clean Code 

Clean code should be elegant and pleasing to read. It should be focused, and you should take care of it. All tests are run in clean code. They shouldn’t contain duplications, and the use of entities, such as classes, methods, and function, should be minimized.

2. Keep your code organized

We need a directory structure that will make it easy to

•         add things as we go,

•         keep the size of our modules manageable,

•         And keep everything in an easy-to-navigate, logical structure.

3. Simplicity

Any software should be created in the most efficient way without unnecessary complexity. Simpler answers are usually more correct, and this thought perfectly meets the needs of the development process. Simplicity coincides with minor coding principles such as Don’t Repeat Yourself (DRY) or You Aren’t Gonna Need It

4. Consistency helps a lot because colleagues will be able to test, edit or continue the work of each other. Vice versa, inharmonious projects can confuse your team and slow down the development process. Here are some tools that will help you enforce a single style:

-> Editorconfig: A system for the unification of code written with different IDEs,

-> ESLint: A highly customizable linter based on node.js,

-> HTML Tidy: Another linter for HTML which also finds errors and;

              -> Stylelint: A linter for CSS with various plugins.

-> Pre-commit hooks- They ensure code isn’t committed unless it meets certain requirements like, linting, testing, commit message of a particular format etc.

5. Accuracy over speed: Focus on correct code instead of fast code. Later it will be easier to speed up processes than rewrite everything and;

6. Experience sharing: Consider exchanging ideas and results with other developers to get external reviews if your project isn’t confidential.

7. Testing

No untested code should find it’s way to production. It’s better for any developer to integrate tests in the development workflow whenever possible.

One can differentiate between test cases like:

a. Unit tests

Testing a single component or function in isolation.

b. Integration tests

Testing interactions between components.

c. End-to-end test

Testing full-blown user flows in the browser.

8. Defining a highly scalable folder structure 

Defining a highly scalable folder structure is recommended  when you aim to build a scalable Angular app. I would suggest you practice a folder structure that is fit for all real-world examples with progressive addition of cases with time if not at the initial phase.

9. Checklist

Maintain a checklist to test the following-

a. Typography- Ensure that the UI matches the prototype. The visual correspondence, the position of the elements, and the distance between them should be similar to those designated in the wireframe. The text should be correct and have no grammatical errors, based on wireframes.

b. Style conformity – Conforming to the brand colors, styles etc. The graphical objects to be used appropriately and according to the guidelines specified in Graphical User Interface Design.

c. Adaptability- Check how it is displayed on all the supported browsers, devices and operating systems.

d. The functionality use- The button clicks, hyperlinks, navigation and other controls to match the needs.

e. Messaging- Look for info, warning and error messaging appropriately, and on what event the feedback is expected to be displayed.

f. Internationalization- Provide for extensibility to support internationalization in the application.


10. Code Linting- Integrate JSLint/ ESLint/ TSLint, CSS Lint with the IDE to ensure uniformity of code.

11. Naming conventions- Follow appropriate naming conventions for the JS/TS, CSS, HTML files and maintain uniform naming style.

12. Coding Style- 


a. Code Commenting- Add comments wherever needed.

b. No hardcoded values, use constants values.

c. Avoid multiple if/else blocks.

d. No commented out code.

e. No unnecessary comments: comments that describe the how.

f. Add necessary comments where needed. Necessary comments are comments that describe the why.

g. Keep components small.

h. Code should have no linting errors.

i. No console logs

j. Avoid inline styles.

k. CSS selectors are only as specific as they need to be, grouped logically.

l. Use Hex codes (#000) in css.


13. Make sure no dist files, editor/IDE files, etc are checked in. There should be a .gitignore for that.

14. Ensure usability of the application from the end user’s perspective, and suggest necessary UX updates.

15. Tests are readable, maintainable, trustworthy.




Tuesday 8 September 2020

React v/s Angular

 

Unless you’ve been living under a rock, you would have heard of two of the trending JS libraries/ frameworks – Angular and React.js. Having worked on both React and Angular, I can without doubt, be called as Jack of all trades… 


A step-by-step comparison of some of them may help you in judging on which path to choose, and start learning, if it interests you, and if you already know either of them, you can relate to the differences and similarities between the two. Like every programming language, frameworks and libraries have their own highly debatable lists of pros and cons!

In this post, you will get to read about how both these frameworks are different and same. First things first, what are Angular and React???

What is Angular?

Angular is a JavaScript framework written in TypeScript. It was developed and is maintained by Google, and is described as a “Superheroic JavaScript MVWFramework” on Angular’s webpage. Angular (version 2 and above), originally released in September 2016, is a complete rewrite of AngularJS (released in October 2010). Angular 9 is the latest version of Angular (at the time of writing this.


What is React.js?

React is a JavaScript library developed and maintained by Facebook. It was released in March 2013 and is described as “a JavaScript library for building user interfaces”.

Developed and maintained by Facebook, React.js is a popular JavaScript library that focuses on building and rendering components for a web page. With React.js, everything is built in JavaScript and I recommend using it with JSX, a JavaScript syntax extension, that “describes what the UI should look like” in your JavaScript code. 

Unlike Angular, it’s not a complete suite of tools, React.js is comprised of tools that help you build components to be dropped into a page. This allows React.js to be lean, but it does require developers to use additional libraries to include functionalities that React.js lacks. For example, routing is not included in React.js, so that would have to be added manually through third-party tools.

How are they similar?

Both React and Angular are both component-based. A component receives an input, and after some internal logic returns a rendered UI template (a sign-in form or a table for example) as output. Components should be easy to reuse within other components or even in other projects. For example, you could have a sign-in component consisting of two text inputs (user & password) and a “Login” button. This component may have various properties and underlying logic, but it should be generalized so that you can reuse the component with different data on another page or in another app.


How are they different?




Let’s compare these JavaScript frameworks and which might make the most sense for your project based on five criteria:
Architecture of React vs. Angular
TypeScript vs JavaScript/Flow
Testing in React vs. Angular
Learning Curve of React vs. Angular
Bundle size


Architecture of React vs. Angular

Angular and React have many similarities and many differences. One of them is that Angular is a full-fledged MVC framework and React is merely a JavaScript Library (just the view). Let me elaborate. Angular is considered a framework because it offers strong opinions as to how your application should be structured. It also has much more functionality “out-of-the-box”. You don’t need to decide which routing libraries to use or other such considerations – you can just start coding. However, a drawback is that you have less flexibility – you must use what Angular provides.
Angular provides the following “out of the box”:
Templates, based on an extended version of HTML
XSS protection
Dependency injection
Ajax requests by @angular/HTTP
Routing, provided by @angular/router
Component CSS encapsulation
Utilities for unit-testing components.
@angular/forms for building forms

React, on the other hand, gives you much more freedom. It only provides the “view” in MVC – you need to solve the M and C on your own. Due to this, you can choose any of your own libraries as you see fit. You will end up using many independent, fast-moving libraries. Because of this, you will need to take care of the corresponding updates and migrations by yourself.
React provides the following “out of the box”:
Instead of classic templates, it has JSX, an XML-like language built on top of JavaScript
XSS protection
No dependency injection
Fetch for Ajax requests
Utilities for unit-testing components

TypeScript vs JavaScript/Flow

React uses JavaScript, a dynamically-typed language (which means you don’t have to define the variable’s type). Because many developers already know and love JavaScript, this can be seen as a pro.
Conversely, if you want to use Angular you’ll need to get comfortable with TypeScript. which is a statically typed language.
Testing in React vs. Angular
Jest is used by Facebook to tests its React code. It is included in every React project and requires zero configuration to use. It also includes a powerful mocking library. Many times Jest is used in combination with Enzyme.
Jasmine is a testing framework that can be used in Angular. Karma and Mocha are the test runners that support running Jasmine test cases.


Learning Curve of React vs. Angular

An important decision you must make in choosing a new technology is its learning curve. The answer depends on your previous experience and familiarity with the related concepts. However, we can still try to assess the number of new things you’ll need to learn before you get started:

React:
The first thing you’ll learn in React is JSX. It may seem awkward to write at first, but it doesn’t add much complexity. You’ll also need to learn how to write components, manage internal state, and use props for configuration. You don’t need to learn any new logical structures or loops since all of this is plain JavaScript.
Once you’re done learning the basics, you’ll need to learn a routing library (since React doesn’t come with one). I recommend react router v4. Next comes state management with Redux or MobX. I’ve already touched upon this subject, so I’ll skip this. Once you’ve learned the basics, a routing library, and state management library, you’re ready to start building apps!

Angular:
Angular has many topics to learn, starting from basic ones such as directives, modules, decorators, components, services, dependency injection, pipes, and templates. After that, there are more advanced topics such as change detection, zones, AoT compilation, and Rx.js.
The entry barrier for Angular is clearly higher than for React. The sheer number of new concepts is confusing to newcomers. And even after you’ve started, the experience might be a bit rough since you need to keep in mind things like Rx.js subscription management and change detection performance.
It may seem like React has a lower barrier for entry, and I would most certainly have to agree. However, that doesn’t mean that React is “better”. I encourage you to try both React and Angular to see which one you personally prefer.
Bundle size
Angular: 1200 KB
React: 300 KB
When using gzip, the sizes go down to 275kb and 127kb respectively.
Conclusion
Choosing the right Javascript frameworks is a real confusion. Especially when you have a lot of options that are super resourceful and capable of facilitating the project requirements. But choosing the one for the right set of projects demands knowledge of several critical aspects. 

Reasons for Choosing Angular:

1. Is a full framework
2. Has a Regular DOM, which renders updates slower than React’s Virtual DOM
3. The rendered JavaScript and HTML maintains a physical separation
4. Utilizes Components: emerging web components standard
5. Data Binding: two-way
6. Testing:  Jasmine & Mocha
7. Learning Curve is higher, but once you understand it you have an entire MVC framework
8. Scalability: easy to scale
9. Popularity: dropped since AngularJS (Angular 1)
10. Open source: GitHub stars: 40,963 / Contributors: 732 / Issue: 2,162
11. Size: larger, resulting in longer load times and performance on mobile
12. Inbuilt features like Rxjs, AngularCLI which are more powerful to create channels of exchanging data and independent handling of events. 
13. It overall optimizes the developers’ efforts and saving lines of code by parallelly running the components 
14. Increases the overall performance 
15. Rapid rendering of server-side, supporting the views that lack browser-side rendering 

Reasons for Choosing React:

1. Just a small view library
2. Has a Virtual DOM, which renders updates faster than Angular’s Regular DOM
3. Uses JSX, which combines markup and logic in the same file (making components easier to read)
4. Data Binding: one-way
5. You Can use ES6/7 JavaScript, although you can use Typescript or Flow if you so choose
6. Mobile: React Native is faster than Angular’s solutions
7. Testing: Jest & Enzyme.
8. Scalability: is more testable, so also easy to scale
9. Popularity: has increased exponentially
10. Size: smaller than Angular, so a bit faster
11. Learning Curve is lower . Unlike Angular, developers have to integrate external entities for access specific functions of Reactjs and gain the fully interactive functionalities
12. It has state containers like Redux for faster development in scalable applications like using the dynamic elements and managing rendering 
13. Using the URL router library like ReactRouter

Let us change our traditional attitude to the construction of programs. Instead of imagining that our main task is to instruct a computer what to to, let us concentrate rather on explaining to human beings what we want a computer to do.
--Donald Knuth

Categories

Agile (1) Angular JS (2) CSS (1) css reset (1) Grunt (1) Jasmine (1) Karma (1) Scrum (1) setup (1) Sprint (1) test cases (1) Typescript (1) UI Automation (1) Webstorm (1)
Disclaimer

The information and images of this blog are sometimes referred from various websites and blogs across the web to provide the best possible content to the reader. The information furnished hereby cannot be used for legal purposes. I will not be liable to you (whether under the law of contact, the law of torts or otherwise) in relation to the contents of, or use of, or otherwise in connection with, this website.