解释型语言的优点和缺点是什么?

发布于 2024-08-08 14:09:11 字数 1436 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

沒落の蓅哖 2024-08-15 14:09:11

公然复制维基百科,所以我将制作这个社区维基。

解释型语言的优点

与编译型语言相比,解释型语言为程序提供了一定的额外灵活性。在解释器中比在编译器中更容易实现的功能包括(但不限于):

  • 平台独立性(例如 Java 的字节码)
  • 反射和求值器的反射使用(例如一阶 eval 函数)
  • 动态类型
  • 易于使用调试(在解释性语言中更容易获得源代码信息)
  • 程序体积小(因为解释性语言可以灵活地选择指令代码)
  • 动态作用域
  • 自动内存管理

解释性语言的缺点

由解释器执行通常比常规程序执行效率低得多。发生这种情况是因为要么每条指令都应该在运行时传递解释,要么在较新的实现中,代码必须在每次执行之前编译为中间表示。虚拟机是性能问题的部分解决方案,因为定义的中间语言更接近机器语言,因此更容易在运行时进行翻译。另一个缺点是需要本地机器上的解释器才能执行。

Blatant copy from wikipedia so I'll make this community wiki.

Advantages of interpreted languages

Interpreted languages give programs certain extra flexibility over compiled languages. Features that are easier to implement in interpreters than in compilers include (but are not limited to):

  • platform independence (Java's byte code, for example)
  • reflection and reflective usage of the evaluator (e.g. a first-order eval function)
  • dynamic typing
  • ease of debugging (it is easier to get source code information in interpreted languages)
  • small program size (since interpreted languages have flexibility to choose instruction code)
  • dynamic scoping
  • automatic memory management

Disadvantages of interpreted languages

An execution by an interpreter is usually much less efficient than regular program execution. It happens because either every instruction should pass an interpretation at runtime or as in newer implementations, the code has to be compiled to an intermediate representation before every execution. The virtual machine is a partial solution to the performance issue as the defined intermediate-language is much closer to machine language and thus easier to be translated at run-time. Another disadvantage is the need for an interpreter on the local machine to make the execution possible.

静水深流 2024-08-15 14:09:11

优点:

  • 快速原型制作(无需编写、编译、执行周期)
  • 跨平台(假设每个平台都存在解释器)

缺点:

  • 性能(不会像编译语言一样快)

Pros:

  • Rapid prototyping (no write, compile, execute cycle)
  • Cross-platform (assuming interpreters exist for each platform)

Cons:

  • Performance (won't be as fast as compiled languages)
意犹 2024-08-15 14:09:11

最大的缺点?大多数人会说执行速度,但并不总是如此。如今,大多数现代解释语言都会在构建时将要解释的文件转换为中间状态,执行时会像任何其他语言一样转换为机器代码。如今,巧妙的缓存在这些语言虚拟机中非常普遍,因此这不应该是一个太大的问题。这当然并不是说性能不是解释性语言的问题,只是它通常并不像大多数人认为的那么糟糕。

请记住,即使存在性能问题,通常也更容易以更少但更高效的代码实现与编译语言相同的任务,从而使得编译期间的性能损失在程序的执行时间内可以忽略不计。

就我个人而言,最大的缺点是在执行之前需要解释器始终存在。这通常会降低可移植性,特别是因为解释语言并不总是跨平台的。

Biggest drawback? Most would say execution speed, but isn't always necessarily true. Most modern interpreted languages these days convert the files to be interpreted into an intermediate state upon building, which when executed is turned into machine code just as any other language. With clever caching being mostly prevalent within these language VMs these days, it shouldn't be too much of an issue. This is certainly not to say that performance is not an issue with interpreted languages, just that it is often not as bad as most would suggest.

Keep in mind that even with the performance problems though, it is often easier to achieve the same tasks as a compiled language in less and more efficient code, making the performance loss during compilation negligible over the execution time of a program.

Personally for me, the biggest drawback is the need for the interpreter to always be present before execution can occur. This quite often reduces portability, especially because interpreted languages aren't always cross platform.

骄兵必败 2024-08-15 14:09:11

缺点:

  • 最大的缺点可能是执行速度

优点:

  • 最大的优点可能是周转时间,即代码测试迭代循环

Con:

  • The biggest drawback is probably execution speed

Pro:

  • The biggest upside is probably turn-around time i.e. code-test iteration loop
浮生未歇 2024-08-15 14:09:11

显而易见的是,编译语言往往比解释语言具有更高的性能,因为编译不需要运行时解释器。

编译语言更适合商业桌面软件,因为源代码不随其一起提供。

解释型语言往往学习起来更快一些,因为它们允许您快速编辑/运行/重复而无需等待编译器。根据我的经验,它们也往往是更高级别的,这也使它们变得更容易。

To put for the obvious and broad point, compiled languages tend to have higher performance than interpreted ones, since compiling precludes the need for a runtime interpreter.

Compiled languages are more suitable for commercial desktop software, since the source code is not shipped along with it.

Interpreted languages tend to be a bit quicker to learn, insofar as they allow you to quickly edit/run/repeat without waiting on a compiler. In my experience they also tend to be higher-level, which makes them easier as well.

故人爱我别走 2024-08-15 14:09:11

维基百科有一个关于优点和缺点的页面。任何非常先进的解释语言都可以实际编译为本机二进制文件,从而模糊了解释语言的优缺点之间的界限。

PERL 是那些模糊界限的语言之一。虽然它以强大的脚本语言而闻名,但您可以将其编译为本机语言。

Wikipedia has a page on the advantages and disadvantages. Any significantly advanced interpreted language can be actual compiled into a native binary thus blurring the lines between the pro's and cons of an interpreted language.

PERL is one of those languages which blurs the lines. Whilst its famous for being a powerful scripting language, you could compile it to be native.

浮华 2024-08-15 14:09:11

PERL 等动态语言的“缓慢”可能不再是问题。以下是关于动态语言领域最新趋势的精彩演示:

http://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html

The "slowness" of Dynamic Languages such as PERL may not be an issue any longer. Here is an excellent presentation on the latest trends in the Dynamic Language area:

http://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html

枉心 2024-08-15 14:09:11

由于java是解释性语言

优点:

  • 兼容性:Java虚拟机认可“一次编写,到处运行”的概念。
  • 安全性:程序在 JVM 中运行,因此如果发生任何故障,不会影响操作系统文件。
  • 内存管理。

缺点:

  • Java虚拟机有多种实现方式,例如,当编写使用Java 8功能的程序时,该程序必须在Java 8版本以上的JVM上运行。

As java is interpreted language

Pros:

  • Compatibility: Java virtual machine approves this concept "Write once, run everywhere."
  • Security: The program running in JVM so if any failure happens this not affects on operating systems files.
  • Memory management.

Cons:

  • Java virtual machine has many implementations, for example when writing a program that uses Java 8 features this program must run on JVM with 8 version not less.
白日梦 2024-08-15 14:09:11

解释型语言的显着优点是不必为每个硬件目标单独编译。

缺点是会使代码执行速度变慢。

The significant benefit of an interpreted language is that it does not have to be compiled for each hardware target separately.

The disadvantage is that it makes the code execution slower.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文