Compiling vs Transpiling

Viewed 57320

While searching about the difference, I came across these definitions:

Compiling is the general term for taking source code written in one language and transforming into another.

Transpiling is a specific term for taking source code written in one language and transforming into another language that has a similar level of abstraction.

I understand what Abstraction is.

But what does "similar level of abstraction" mean in the above definition? And how do we find the level of abstraction in a language?

8 Answers

Ex: TypeScript ( a Microsoft superset of JavaScript with type safe checking) transpiles to JavaScript code which can run on different types of browsers.

https://en.wikipedia.org/wiki/Microsoft_TypeScript "Microsoft TypeScript is an open-source programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript, and adds optional static typing to the language.

TypeScript is designed for development of large applications and transcompiles to JavaScript.[5] As TypeScript is a superset of JavaScript, existing JavaScript programs are also valid TypeScript programs. TypeScript may be used to develop JavaScript applications for both client-side and server-side (Node.js) execution."

I mostly agree with tapananand answer, but...


definition

Words are "made", so they serve a purpose. And this also changes with time.

We now tend to use transpiler to specify a compiler that translates code into some other code "more similar" to the source one, that what a compiler might do. And is used to differentiate both mostly when both of them are mentioned in the same context (again mostly implying that a transpile language will have to get compiled at least once more)


examples

So everything is very subjective. At the time of this writing:

  • Coming from the Java world I could call CoffeeScript/TypeScript transpilers to depict that the resulting code is no more efficient than the original one.
  • CoffeScript documentation says it's a compiler, and babel is a transpiler. The want do say that CoffeeScript, although very similar, is not Javascript. At least not a version of it, as that is what babel produces.
  • Babel calls itself a compiler.

fazit

So transpile is at this time very rarely used anymore, and only to tell two compilers apart.

It will probably dissapear as concept, since compilation is much more complicated than that (same/higher/lower language, version, etc), and the word doesn't seem to be useful anymore ("transpilers" are now ubiquitous)

Meaning of "similar level of abstraction"

Higher level languages are more abstracted than lower level languages. By abstracted I mean easier to understand.

Higher level language(highly abstracted)---- Similar level -----> Higher level Another language(highly abstracted)
(TypeScript Source code to JavaScript Source code)

Mid level language(poorly abstracted) ---- Similar level-----> Mid level language(poorly abstracted)

Higher level language(highly abstracted) ---- Not Similar level of abstraction -----> Mid level Another language(poorly abstracted)

Computers only understand 1s and 0s: You can think of computer as being a box, crammed full of switches - kinda like a light switch: they can either be "on" or "off" - they can either be a "1" or a "0". You can instruct a computer which switches you want on or off, with a series of "1s" and "0s".

People need programming languages: Human beings are not very good at reading/understanding hundreds of thousands of lines of "1s" and "0s"........ but we can be trained to understand human words: like: class and break.

Programming languages allow us to write computer instructions, which can be translated into 1s and 0s (compiling), or which can be translated into other programming languages. for example: if you have elm code, you can easily transform that into javascript (transpiling).

The word "pre‎processor" often used as synonym for "transpiler".

The word "preprocessor" was already well-known in the 90th and emphasises that something is processed before something else. It is also used in a context of removing comments before code is compiled.

The word "transpiler" became more popular in the 2010th (I heared it first 2015 from a colleague with contact to AngularJS community), calling the process of bringing TypeScript to JavaScript as "transpiling" - as some kind of trans‎lation that is like a com‎pilation (checking data-types etc.).

To sum it up:

  • "Transpilation" fits best when something is translated with some compilation-like functionalities.
  • "Preprocessor" is a more generic term where basically something is processed before.

Compilers are used to compile source code written in one language to another. A compiler will often use the same syntax as the input language, but it may also be designed for some other type of input, like bytecode.

Transpilers are different because they translate code from one programming language to another. The original program may have been written in JavaScript, but the transpiler converts it into HTML.

Related