Compiling Vs Transpiling — What and Why?
We’ll dive into the main topic shortly, but first…
What are low-level languages and high-level languages?
Low-level languages are the ones that computer understands. It is very close to writing actual machine instructions. The code is not human-readable, and it is often cryptic. For example Assembly language and Machine language (0s and 1s)
High-level languages are the programming languages that are more human-readable. Unlike Sheldon Lee Cooper, humans have a tough time understanding, debugging, and maintaining low-level code. So, we need layers and layers of abstraction to write meaningful code. For example Java, C++, JavaScript, and many more
What is compiling?
Compiling is the process of converting a high-level programming language to a low-level programming language.
But why do we need to compile our code?
As you already know, the computer understands low-level language, so in order to actually make our program run, we need to convert our language to something which the computer can understand.
Sometimes it’s compiled in multiple steps, each step optimizing the code and getting it closer to machine code.
For example, Java, C#, and C are a few examples of the high-level languages that are needed to be compiled.
What is transpiling?
Also, know as ‘transcompiling’
Transpiling is converting one high-level language to another high-level language.
But why do we need to transpile a high-level language?
You’ve probably heard about CoffeeScript and TypeScript. Anything you can write in JavaScript, you can write in CoffeeScript or TypeScript.
But the problem is, JavaScript environments only understand … Well, JavaScript.
Enter *drumrolls* — Transpilers. They read CoffeeScript, TypeScript, and ES2015, and spit out JavaScript guaranteed to work anywhere.
A common example of a transpiler is Babel. It is used to convert ES6+ code into backward-compatible versions of Javascript.