Absorb Knowledge in 30 Seconds | Brain Bytes #4
Loïc Boset
Posted on August 23, 2021
Recap 🧠
Brain Bytes is a knowledge platform where you can learn new things about software development in less than 30 seconds.
Bytes of the Week
Monolithic vs. Microservices Architecture
With monolithic architectures, all processes are tightly coupled and run as a single service. This means that if one process of the application experiences a spike in demand, the entire architecture must be scaled.
Monolithic architectures add risk for application availability because many dependent and tightly coupled processes increase the impact of a single process failure.
With a microservices architecture, an application is built as independent components that run each application process as a service. These services communicate via a well-defined interface using lightweight APIs. Because they are independently run, each service can be updated, deployed, and scaled to meet demand for specific functions of an application.
Javascript hoisting
JavaScript Hoisting refers to the process whereby the compiler allocates memory for variable and function declarations prior to the execution of the code. In other words, the compiler moves the variables declaration to the top of the code.
In the below example, the catName
function is called before it is written and the code still works.
catName("Chloe");
function catName(name) {
console.log("My cat's name is " + name);
}
// "My cat's name is Chloe"
IIFE (Immediately Invoked Function Expression)
An IIFE is a JavaScript function that runs as soon as it is defined.
(function(value){
const greet = 'Hello ';
console.log(greet + value);
})('world');
// "Hello world"
A use case for IIFE is to avoid polluting the namespace. If you have some initiation code that you don't need to use again, you could use the IIFE pattern.
Javascript Generator Functions
The function* declaration (function keyword followed by an asterisk) defines a generator function, which returns a Generator object.
Generators are functions that can be exited and later re-entered.
They can be useful for example for creating infinite loops (such as an id generator) or solving problems with Callback Hell and Inversion Control.
function* generator(i) {
yield i;
yield i + 10;
}
const gen = generator(10);
console.log(gen.next().value);
// expected output: 10
console.log(gen.next().value);
// expected output: 20
Imperative vs Declarative Programming
The imperative paradigm is focused on HOW to do things. The declarative paradigm is focused on WHAT we want to achieve.
Imperative code example
function double(array) {
let results = [];
for (let i = 0; i < array.length; i++) {
results.push(array[i] * 2)
}
return results
}
Declarative code example
function double(array) {
return array.map((item) => item * 2)
}
Scripting language
A scripting language is a series of commands that are able to be executed without the need for compiling.
Scripting languages use a program known as an interpreter to translate commands and are directly interpreted from source code, not requiring a compilation step. Other programming languages, on the other hand, may require a compiler to translate commands into machine code before it can execute those commands.
JavaScript, Python, and Ruby are all examples of scripting languages.
Compiler
A compiler is a computer program that translates code written in one programming language (the source language) into another language (the target language).
The name "compiler" is primarily used for programs that translate source code from a high-level programming language to a lower level language (e.g. assembly language, object code, or machine code) to create an executable program.
High-level programming language
A high-level programming language is a programming language with strong abstraction from the details of the computer.
In contrast to low-level programming languages, it may use natural language elements, be easier to use, or may automate (or even hide entirely) significant areas of computing systems (e.g. memory management), making the process of developing a program simpler and more understandable than when using a lower-level language.
Python, Visual Basic, PHP, Javascript, Ruby, C#, and Java are examples of high-level programming languages.
Come and participate!
Brain Bytes is an open source project, so reach out to me to participate in its development! There is plenty to do!
Come now and share your knowledge!
Thanks for reading 🙏 ❤️
Posted on August 23, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.