Transpiler and Compiler

Transpiler and Compiler

ยท

3 min read

There are lot of confusion about Transpiler and compiler that they are similar but actually are they ?? Lets find out !!!

Compiling and transpiling have very similar defination but they are not the same . So what are the differences between these two ??๐Ÿค”๐Ÿค”

If we just go down into how computers operate , as we all know they are in the form of 0's and 1's . But we humans don't write our code in the terms of 0's and 1's . We have lot of programming languages to write our code . When we write our code then it gets converted into machine understandable language . That's when compilers comes into the picture .

High and Low level languages

Computer programming languages are broadly classified into 2 categories which are High and Low level programming language. A high-level language is one that is easier for humans to read and write. Higher level are languages more abstracted than lower level languages. By abstracted we mean easier to understand.

Abstraction in simple terms means hiding low level details from the higher ones . Lets take an example to understand -

If a man is driving a car .The man only knows that pressing the accelerators will increase the speed of a car or applying brakes will stop the car, but he does not know about how on pressing the accelerator the speed is actually increasing, he does not know about the inner mechanism of the car. This is what abstraction is.

Compiler

When we write our code in a high-level language, depending on the language used, a conversion takes place where the high-level code is converted into lower-level code. This conversion, formally known as compiling, it is done with the help of compiler .

Compilers also convert the code from one language to other language but both languages are very different in abstraction level. For example, Java compiler converts the .java file to .class file.

Usually every programming language have it's own compiler(except for javascript).

1_Qbm5_d5EYIbYa1-jN4JmSg.jpeg

Transpiler

Transpilers, or source-to-source compilers, are tools that read the source code written in one programming language and produce the equivalent code in another programming language with a similar level of abstraction.

Basically it converts ES6 JavaScript code to ES5 JavaScript code so that it can run in browsers. When the transpiler sees an expression that uses a language feature that needs to be translated, it produces a logically equivalent expression.

A good example of transpiler is the Typescript transpiler which converts Typescript code to JavaScript. Similarily,Babel transpiler can also be used for converting the ES6 JS code to ES5 JS source code.

xEnE8EPwf.jpg

This is the basic difference between transpiler and compiler, we can further explore the topic with the help of code.

Happy Learning !!

ย