• Compiling vs Transpiling


    Compiling vs Transpiling

    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? 

    回答

    The definition you have quoted above is too general for a beginner to understand completely and so let me just simplify it to something we see practically.

    Compiler: is an umbrella term to describe a program that takes source code written in one language and produce a (or many) output file in some other language. In practice we mostly use this term to describe a compiler such as gcc which takes in C code as input and produces a binary executable (machine code) as output.

    Transpilers are also known as source-to-source compilers. So in essence they are a subset of compilers which take in a source code file and convert it to another source code file in some other language or a different version of the same language. The ouput is generally understandable by a human. This output still has to go through a compiler or interpreter to be able to run on the machine.

    Some examples of transpilers:

    1. Emscripten: Transpiles C/C++ to JavaScript
    2. Babel: Transpiles ES6+ code to ES5 (ES6 and ES5 are different versions or generations of the JavaScript language)

    Now, what do they mean by "similar level of abstraction": As I said it compiles/transpiles to a source file, one can argue that assembly language is also a source file and thus gcc is also a transpiler. So, this argument is what this similar level of abstraction voids.

    The notion of categorizing languages into lower, middle and higher level is based on the level of abstraction they provide from the actual working of the machine/architecture.

    Lower level languages like assembly are very close to the processor architecture i.e. have different instructions for different processors. While C/C++/Java/JavaScript, abstract all this away providing more abstraction.

    So, a transpiler compiles to a language that is closer to the language you started with in the terms of this abstraction (or is closer to the level of that language in the lower-middle-higher level language ladder).

    Hope this helps!

  • 相关阅读:
    ng-class中的if else判断
    Sass 的使用
    pre 标签的使用
    C++操作 SQL数据库 实例 代码步骤
    自己写的一个操作Mysql的简单的实例
    C++ 链接Mysql 函数介绍
    Mysql 操作命令 详解
    MFC程序开始的执行过程详述
    Java各种日期格式的获取和设置指定日期
    DM8168 OpenCV尝试与评估(编译ARM版OpenCV)
  • 原文地址:https://www.cnblogs.com/chucklu/p/14308072.html
Copyright © 2020-2023  润新知