Transpiling V/s Compiling

Transpiling V/s Compiling

The blog is all about transpiler and compiler and their process. It also includes the advantages and the types along with examples for better understanding.

TRANSPILING

What is a transpiler? Transpilers, are tools that read the source code written in one language and produce the equivalent code in another language with a similar level of abstraction. It is also known as source-to-source compilers.

image.png

How transpiler works? Transpiling is the type of compilation. It switches one language (or version of a language) to another at the same number(abstraction level).

Abstraction - It refers to the important things that are visible to the user and all the working which is irrelevant to the user is hidden.

The lower the number the lower is the abstraction level.

  1. CPU-level (actual logic gates on the CPU)
  2. machine code
  3. assembly code
  4. [C/C++, JVM/bytecode]
  5. [JavaScript, Python]

What is transpiling? Transpiling is the process in which the transpilers convert the source code from one language/version of the language to another language/version at the same abstraction level.

Types of transpiler There are different types of transpilers, as per the source and target language.

E.g Babel transpiler is the most popular and commonly used for converting the ES6 JS code to ES5 JS source code or any lower version.

image.png

Advantages of transpilers Transpiler's goal is that programmers do not need to rewrite or duplicate code anymore. When a new language or library comes up, programmers should be able to use and tune transpilers so legacy code does not turn out to be obsolete.

Also, taking the example of JS. The browser compatibility to the code comes into the picture. As of today, most of the browsers are compatible with ES5 and not with ES6 yet as to make a browser compatible with the new language/syntax there is a long process by when we may expect a new language/version

So, it's not as important as a compiler but has its own uses and advantages.

COMPILING

What is a compiler? A compiler is a program that processes statements written in a particular language and turns them into machine language or "code".

image.png

Machine code is the binary code i.e written in 0s and 1s and understood by the machine and hence known as machine code.

Types of compilers There are multiple compilers used for different purposes. The common ones are:

  • ahead-of-time (AOT) compilers: These are typically invoked from the command line in a shell environment (from within a terminal or console) or within an IDE.

  • just-in-time (JIT) compilers: These are typically not invoked directly but are instead built into software runtimes internally, for the purpose of improving performance.

How compiler works? image.png The compiler takes the code and converts it into machine code as per the definition and the output is received.

Most compilers perform either ahead-of-time (AOT) compilation or just-in-time (JIT) compilation.

What is compiling? The process of converting a high-level code(javascript/typescript) written in any language to a low-level code/machine code is known as compilation/ compiling.

image.png

Advantages of compiling The machine won't understand a thing if the code is not compiled. So to perform any and every operation on the machine, the compilation of code is a must which leaves us with no cons.

SUMMARY image.png

Did you find this article valuable?

Support Parull Kohhli by becoming a sponsor. Any amount is appreciated!