Ruby 是脚本语言还是解释语言?

发布于 2024-12-02 10:13:35 字数 164 浏览 2 评论 0原文

我刚刚注意到在Ruby的维基百科页面中,这种语言被定义为解释性语言。
我明白我的背景可能缺少一些东西。
我一直都知道不需要编译器的解释语言和编译语言(需要在程序执行之前进行编译)之间的区别,但是什么描述脚本语言的特征?
Ruby 可以定义为脚本语言吗?

谢谢你并原谅我的停电

I just noticed that in the wikipedia page of Ruby, this language is defined as interpreted language.
I understood that probably there's something missing in my background.
I have always known the difference between an interpreted language that doesn't need a compiler and a compiled language (who require to be compiled before the execution of programs), but what characterize a scripting language ?
Is Ruby definable as a scripting language ?

Thank you and forgive me for the black out

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

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

发布评论

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

评论(3

握住我的手 2024-12-09 10:13:35

事情不仅仅是黑白的。至少,它们也有大和小、响亮和安静、蓝色和橙色、灰色和灰色、长和短、对和错等等。

解释/编译只是语言分类的一种方式,它是完全独立的无论您是否将同一种语言称为“脚本语言”,(以及无数其他事情)。最重要的是,它也是一个破碎的分类:

  • 语言(这不仅仅是理论,确实有相当多的语言同时存在解释器和编译器)。
  • 解释/编译取决于语言实现,而不取决于 (其中很多,包括大多数 Ruby 实现)都是编译器,但“仅”编译为字节码并解释该字节码。
  • 还有一些实现可以在解释和编译为本机代码(JIT 编译器)之间切换。

你看,现实是一头复杂的野兽;)如上所述,Ruby 经常被编译。然后解释该编译的输出,至少在某些情况下是这样 - 还有一些实现是 JIT 编译的(Rubinius 和 IIRC JRuby 会在一段时间后编译为 Java 字节码)。参考实现长期以来一直是编译器,IIRC 仍然如此。那么 Ruby 是解释型还是编译型?除非您定义它,否则这两个术语都没有意义;)

但回到问题:“脚本语言”也不是该语言的属性,它取决于该语言的使用方式 - 即该语言是否用于脚本任务。如果您正在寻找定义,“脚本语言”上的维基百科页面可能会有所帮助(只是不要让他们使您对实现细节的注释感到困惑,例如通常解释脚本)。确实有一些程序使用 Ruby 来执行脚本任务,并且毫无疑问有许多独立的 Ruby 程序可能符合脚本的资格(网络抓取、系统管理等)。

所以是的,我想人们可以将 Ruby 称为一种脚本语言。当然,这并不意味着 Ruby on Rails Web 应用程序只是一个脚本。

Things aren't just black and white. At the very least, they're also big and small, loud and quiet, blue and orange, grey and gray, long and short, right and wrong, etc.

Interpreted/compiled is just one way to categorize languages, and it's completely independent from (among countless other things) whether you call the same language a "scripting language" or not. To top it off, it's also a broken classification:

  • Interpreted/compiled depends on the language implementation, not on the language (this is not just theory, there are indeed quite a few languages for which both interpreters and compilers exist)
  • There are language implementations (lots of them, including most Ruby implementations) that are compilers, but "only" compile to bytecode and interpret that bytecode.
  • There are also implementations that switch between interpreting and compiling to native code (JIT compilers).

You see, reality is a complex beast ;) Ruby is, as mentioned above, frequently compiled. The output of that compilation is then interpreted, at least in some cases - there are also implementations that JIT-compile (Rubinius, and IIRC JRuby compiles to Java bytecode after a while). The reference implementation has been a compiler for a long time, and IIRC still is. So is Ruby interpreted or compiled? Neither term is meaningful unless you define it ;)

But back to the question: "Scripting language" isn't a property of the language either, it depends on how the language is used - namely, whether the language is used for scripting tasks. If you're looking for a definition, the Wikipedia page on "Scripting language" may help (just don't let them confuse you with the notes on implementation details such as that scripts are usually interpreted). There are indeed a few programs that use Ruby for scripting tasks, and there are doubtless numerous free-standing Ruby programs that would likely qualify as scripts (web scraping, system administration, etc).

So yes, I guess one can call Ruby a scripting language. Of course that doesn't mean a ruby on rails web app is just a script.

眼泪也成诗 2024-12-09 10:13:35

是的。

详细响应:

脚本语言通常用于控制通常不是用该语言编写的应用程序。例如,shell脚本等可以调用任意控制台应用程序。

Ruby 是一种通用动态语言,经常用于脚本编写。

您可以使用反引号表示法进行任意系统调用,如下所示。

`<system command>`

还有许多优秀的 Ruby gem,例如 WatirRAutomation 用于自动化 Web 和本机 GUI。

有关脚本语言的定义,请参阅此处

Yes.

Detailed response:

A scripting language is typically used to control applications that are often not written in this language. For example, shell scripts etc. can call arbitrary console applications.

Ruby is a general purpose dynamic language that is frequently used for scripting.

You can make arbitrary system calls using backtick notation like below.

`<system command>`

There are also many excellent Ruby gems such as Watir and RAutomation for automating web and native GUIs.

For definition of scripting language, see here.

笑梦风尘 2024-12-09 10:13:35

“脚本语言”这个术语非常广泛,它可以包括解释型语言和编译型语言。特别是 Ruby,可能会根据我们使用的特定实现进行编译或解释 - 例如,JRuby 被编译为字节码,而 CRuby(Ruby 的参考实现)则被解释。

The term "scripting language" is very broad, and it can include both interpreted and compiled languages. Ruby in particular, might be compiled or interpreted depending on what particular implementation we're using - for instance, JRuby gets compiled to bytecode, whereas CRuby (Ruby's reference implementation) is interpreted.

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