编译语言与解释语言 [英] Compiled vs. Interpreted Languages

查看:28
本文介绍了编译语言与解释语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力更好地了解差异.我在网上找到了很多解释,但它们倾向于抽象差异而不是实际含义.

I'm trying to get a better understanding of the difference. I've found a lot of explanations online, but they tend towards the abstract differences rather than the practical implications.

我的大部分编程经验都是使用 CPython(动态、解释型)和 Java(静态、编译型).但是,我知道还有其他类型的解释型和编译型语言.除了可执行文件可以从用编译语言编写的程序分发的事实之外,每种类型有什么优点/缺点吗?经常听到有人争论解释型语言可以交互使用,但我相信编译型语言也可以有交互实现,对吗?

Most of my programming experiences has been with CPython (dynamic, interpreted), and Java (static, compiled). However, I understand that there are other kinds of interpreted and compiled languages. Aside from the fact that executable files can be distributed from programs written in compiled languages, are there any advantages/disadvantages to each type? Oftentimes, I hear people arguing that interpreted languages can be used interactively, but I believe that compiled languages can have interactive implementations as well, correct?

推荐答案

编译语言是一种编译语言,其中程序一旦被编译,就会在目标机器的指令中表达.例如,源代码中的加法+"操作可以直接转换为机器代码中的ADD"指令.

A compiled language is one where the program, once compiled, is expressed in the instructions of the target machine. For example, an addition "+" operation in your source code could be translated directly to the "ADD" instruction in machine code.

解释型语言是一种指令不直接由目标机器执行,而是由其他程序(通常用本地机器的语言编写)读取和执行的语言.例如,解释器会在运行时识别相同的+"操作,然后它会使用适当的参数调用自己的add(a,b)"函数,然后执行机器代码ADD"指令.

An interpreted language is one where the instructions are not directly executed by the target machine, but instead read and executed by some other program (which normally is written in the language of the native machine). For example, the same "+" operation would be recognised by the interpreter at run time, which would then call its own "add(a,b)" function with the appropriate arguments, which would then execute the machine code "ADD" instruction.

你可以用编译型语言用解释型语言做任何你能做的事情,反之亦然——它们都是图灵完备的.然而,两者在实现和使用上各有优缺点.

You can do anything that you can do in an interpreted language in a compiled language and vice-versa - they are both Turing complete. Both however have advantages and disadvantages for implementation and use.

我将完全概括(纯粹主义者原谅我!)但是,粗略地说,以下是编译语言的优点:

I'm going to completely generalise (purists forgive me!) but, roughly, here are the advantages of compiled languages:

  • 直接使用目标机器的本机代码提高性能
  • 有机会在编译阶段应用非常强大的优化

以下是解释型语言的优点:

And here are the advantages of interpreted languages:

  • 更容易实现(编写好的编译器非常难!!)
  • 无需运行编译阶段:可以直接即时"执行代码
  • 可以更方便地使用动态语言

请注意,字节码编译等现代技术增加了一些额外的复杂性——这里发生的情况是编译器针对的是与底层硬件不同的虚拟机".这些虚拟机指令可以在稍后阶段再次编译以获得本机代码(例如,由 Java JVM JIT 编译器完成).

Note that modern techniques such as bytecode compilation add some extra complexity - what happens here is that the compiler targets a "virtual machine" which is not the same as the underlying hardware. These virtual machine instructions can then be compiled again at a later stage to get native code (e.g. as done by the Java JVM JIT compiler).

这篇关于编译语言与解释语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆