DEV Community

tupe12334
tupe12334

Posted on

Compilation vs. Transpilation

TLDR

Compilation is the process of turning source code into machine code, while transpilation is the process of turning source code from one high-level language into another.

Background story

Today I had a conversation with two of my colleagues about the difference between compilation and transpilation. They asked me to explain it to them in simple terms, and I thought it would be a great idea to write an article about it for anyone who might be wondering about the same thing.

Compilation and transpilation are both processes that involve turning source code written in one programming language into another. However, there are some key differences between the two that I will explain below.

Compilation

Compilation is the process of converting source code written in a high-level programming language (such as C++ or Java) into machine code that can be run on a computer. This machine code is specific to the type of processor that the computer is using and is generally not readable by humans. Compiling source code allows it to be run more efficiently on a computer, as the machine code is optimized for the specific processor it is being run on.

Transpilation

Transpilation, on the other hand, involves converting source code from one high-level programming language into another. For example, transpiling TypeScript to JavaScript involves taking source code written in TypeScript and converting it into JavaScript. This process is often used to allow code written in newer or less widely-used programming languages to be used in environments where those languages are not supported.

Typescript and JavaScript

One example of transpilation in action is the conversion of TypeScript code to JavaScript. TypeScript is a programming language that was developed by Microsoft and is a superset of JavaScript. It adds features to JavaScript such as static typing and class-based object-oriented programming, which can make it easier to write large-scale applications. However, not all environments support TypeScript, so transpiling it to JavaScript allows it to be used in those environments.

Feel free to contact me

I hope this explanation of the difference between compilation and transpilation has been helpful! If you have any questions or would like further information, please don't hesitate to ask.

Full Disclosure

I used tools such as ChatGPT and Grammarly to help me write this article. These tools assisted in the writing process by suggesting alternative phrases and correcting grammar errors, but the content of the article is entirely my own work.

Top comments (0)