30

What are the main differences between a Compiler and a Transpiler? Please could you provide some examples of both?

Dave
  • 498
  • 2
  • 7
  • 22
Dawlatzai Ghousi
  • 3,780
  • 2
  • 20
  • 26
  • 3
    Possible duplicate of [Compiler Vs Interpreter Vs Transpiler](http://stackoverflow.com/questions/39246498/compiler-vs-interpreter-vs-transpiler) – xmojmr Nov 15 '16 at 09:17

2 Answers2

33

They're essentially the same: take source code and transform it to something else.

The difference is that compiler usually produces a directly usable artifact (executable binary of some sort). Example: C (produces binary), C# (produces bytecode).

Whereas transpiler produces another form of source code (in another language, for example), which is not directly runnable and needs to be compiled/interpreted. Example: CoffeeScript transpiler, which produces javascript. Opal (converts ruby to javascript)

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
4

Compiler - compiles code to a lower level code.

Example:

  • "Developer code" -> "Machine code"
  • PHP -> C
  • Java -> bytecode

Transpiler - compiles code to same level of code/abstraction.

Example:

  • "Developer code" -> "Another developer code or version"
  • JavaScript ES2015+ -> JavaScript ES5
Jim M
  • 4,261
  • 1
  • 18
  • 15