🤜🤛Compiler vs Transpiler

·

2 min read

🤜🤛Compiler vs Transpiler

Compiler vs Transpiler

I was attending the first lecture of neogcamp’22 and a question, out of multiple others, was raised asking the difference between a compiler and a transpiler.

Then, I too had no idea about the differences so ended up doing some deep dive on the topic. Below I am trying to explain what I understood in the easiest language I can.


Before we learn about compilers and transpilers, we have to understand that broadly programming languages are of two types or levels viz.
High level Language and Low level Language.

  • High Level languages
    are human friendly languages or to be specific, programmer friendly languages. These are written in formats easy to understand by a programmer, they are easy to debug and simple to maintain. Examples: C, C++, Java, Python, Javascript.

  • Low Level Language
    is machine /computer friendly language and written in Binary (0 and 1).
    It is understood by computers but very hard to understand by humans, hence difficult to debug and complex to maintain.


Why are conversions needed though?

When two person interacting speaks and understand different languages, a translator is required to convey the message, similarly in programming world, for a computer to understand the “set of instructions” conversion of the high level language to lower level in required and vice verse.

Coming back to the main topic,
A Compiler is a program that takes a source code (HLL) and converts it into some Low level language (generally machine code). An umbrella that encompasses Transpilers too.

A Transpiler is also a program that takes a source code and converts it into a source code of a different High level language or a different version of the same language. The output is still human understandable, and will eventually have to go through a compiler before running on a machine.

Examples:

  • Typescript transpiler which converts Typescript code to JavaScript
  • Babel transpiler can also be used for converting the ES6 JS code to ES5 code.

This is what I understood I so far and wrote in the most vanilla way possible. I know there are multiple branches here that can be further deep dived upon, will keep on updating this as my learning grows.

Thanks for reading.

Â