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!

  • 相关阅读:
    sass安装与使用
    前端兼容性问题
    springboot项目数据库错误记录
    C#实现微信聊天对话框
    关于html的多行匹配,正则re.S的使用(爬取豆瓣电影短评)
    判断网页能否打开?python
    利用python爬取点小图片,满足私欲(爬虫)
    ajax加载时的进度条
    java 发送微信客服消息
    Fastjson Mysql JDBC 反序列化
  • 原文地址:https://www.cnblogs.com/chucklu/p/14308072.html
Copyright © 2011-2022 走看看