解释型和编译型编程语言_解释型和编译型编程语言:有什么区别?

解释型和编译型编程语言

Every program is a set of instructions, whether it’s to add two numbers or send a request over the internet. Compilers and interpreters take human-readable code and convert it to computer-readable machine code.

每个程序都是一组指令,无论是添加两个数字还是通过Internet发送请求。 编译器和解释器将人类可读的代码转换为计算机可读的机器代码。

In a compiled language, the target machine directly translates the program. In an interpreted language, the source code is not directly translated by the target machine. Instead, a different program, aka the interpreter, reads and executes the code.

目标计算机以编译语言直接翻译程序。 在一种解释性语言中,源代码不会直接由目标计算机翻译。 而是由另一个程序(也称为解释器)读取并执行代码。

好的,但这实际上是什么意思? (Okay… but what does that actually mean?)

Imagine you have a hummus recipe that you want to make, but it's written in ancient Greek. There are two ways you, a non-ancient-Greek speaker, could follow its directions.

想象您有一个鹰嘴豆泥食谱要制作,但是它是用古希腊语写的。 作为非古希腊语讲者,您可以通过两种方式遵循其指示。

The first is if someone had already translated it into English for you. You (and anyone else who can speak English) could read the English version of the recipe and make hummus. Think of this translated recipe as the compiled version.

首先是有人已经为您翻译成英文。 您(以及其他会讲英语的人)可以阅读食谱的英文版本,做鹰嘴豆泥。 将此翻译的配方视为编译版本。

The second way is if you have a friend who knows ancient Greek. When you're ready to make hummus, your friend sits next to you and translates the recipe into English as you go, line by line. In this case, your friend is the interpreter for the interpreted version of the recipe.

第二种方法是,如果您有一位了解古希腊语的朋友。 当您准备制作鹰嘴豆泥时,您的朋友会坐在您旁边,并逐步将食谱翻译成英文。 在这种情况下,您的朋友是食谱解释版本的解释者

编译语言 (Compiled Languages)

Compiled languages are converted directly into machine code that the processor can execute. As a result, they tend to be faster and more efficient to execute than interpreted languages. They also give the developer more control over hardware aspects, like memory management and CPU usage.

编译的语言直接转换为处理器可以执行的机器代码。 结果,它们往往比解释语言更快,更高效地执行。 它们还使开发人员可以更好地控制硬件方面,例如内存管理和CPU使用率。

Compiled languages need a “build” step – they need to be manually compiled first. You need to “rebuild” the program every time you need to make a change. In our hummus example, the entire translation is written before it gets to you. If the original author decides that he wants to use a different kind of olive oil, the entire recipe would need to be translated again and resent to you.

编译语言需要一个“构建”步骤-首先需要对其进行手动编译。 每次需要进行更改时,您都需要“重建”程序。 在我们的鹰嘴豆泥示例中,整个翻译是在您到达之前编写的。 如果原始作者决定他要使用其他种类的橄榄油,则需要重新翻译整个食谱并重新发送给您。

Examples of pure compiled languages are C, C++, Erlang, Haskell, Rust, and Go.

纯编译语言的示例是C,C ++,Erlang,Haskell,Rust和Go。

口译语言 (Interpreted Languages)

Interpreters run through a program line by line and execute each command. Here, if the author decides he wants to use a different kind of olive oil, he could scratch the old one out and add the new one. Your translator friend can then convey that change to you as it happens.

口译员逐行执行程序并执行每个命令。 在这里,如果作者决定使用其他种类的橄榄油,则可以将旧的橄榄油​​划掉,然后添加新的橄榄油。 然后,您的翻译朋友可以随时将更改传达给您。

Interpreted languages were once significantly slower than compiled languages. But, with the development of just-in-time compilation, that gap is shrinking.

口译语言曾经远比编译语言慢。 但是,随着即时编译的发展 ,这种差距正在缩小。

Examples of common interpreted languages are PHP, Ruby, Python, and JavaScript.

常见解释语言的示例是PHP,Ruby,Python和JavaScript。

一个小警告 (A Small Caveat)

Most programming languages can have both compiled and interpreted implementations – the language itself is not necessarily compiled or interpreted. However, for simplicity’s sake, they’re typically referred to as such.

大多数编程语言可以同时具有编译和解释的实现-语言本身不一定是编译或解释的。 但是,为简单起见,通常将它们称为此类。

Python, for example, can be executed as either a compiled program or as an interpreted language in interactive mode. On the other hand, most command line tools, CLIs, and shells can theoretically be classified as interpreted languages.

例如,Python可以在交互模式下作为编译程序或解释语言执行。 另一方面,大多数命令行工具,CLI和外壳程序在理论上可以归类为解释语言。

的优点和缺点 (Advantages and disadvantages)

编译语言的优势 (Advantages of compiled languages)

Programs that are compiled into native machine code tend to be faster than interpreted code. This is because the process of translating code at run time adds to the overhead, and can cause the program to be slower overall.

编译为本地机器代码的程序往往比解释的代码要快。 这是因为在运行时翻译代码的过程增加了开销,并可能导致程序整体变慢。

编译语言的缺点 (Disadvantages of compiled languages)

The most notable disadvantages are:

最明显的缺点是:

  • Additional time needed to complete the entire compilation step before testing

    测试之前完成整个编译步骤需要额外的时间
  • Platform dependence of the generated binary code

    生成的二进制代码的平台依赖性

口译语言的优势 (Advantages of interpreted languages)

Interpreted languages tend to be more flexible, and often offer features like dynamic typing and smaller program size. Also, because interpreters execute the source program code themselves, the code itself is platform independent.

口译语言趋向于更灵活,并且经常提供诸如动态键入和较小程序大小的功能。 另外,由于解释器自己执行源程序代码,因此代码本身是平台无关的。

解释语言的缺点 (Disadvantages of interpreted languages)

The most notable disadvantage is typical execution speed compared to compiled languages.

与编译语言相比,最明显的缺点是典型的执行速度。

翻译自: https://www.freecodecamp.org/news/compiled-versus-interpreted-languages/

解释型和编译型编程语言

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值