zoukankan      html  css  js  c++  java
  • 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!

  • 相关阅读:
    python 输出时间格式化及前一天、前一秒时间
    python双色球选号生成
    python爬虫练习
    python爬虫之BeautifulSoup4介绍
    装饰器
    *args和**kwargs
    (二)python爬虫实例:猫眼电影TOP100榜并将电影信息写入到Excel(Excel列宽自适应)
    (一)python爬虫实例:猫眼电影TOP100榜并将电影信息写入到Excel
    python安装库时,pip install xxx下载慢以及超时失败的问题解决
    python之高阶函数map()reduce()filter()
  • 原文地址:https://www.cnblogs.com/chucklu/p/14308072.html
Copyright © 2011-2022 走看看