Ruby 是脚本语言还是解释语言?
我刚刚注意到在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事情不仅仅是黑白的。至少,它们也有大和小、响亮和安静、蓝色和橙色、灰色和灰色、长和短、对和错等等。
解释/编译只是语言分类的一种方式,它是完全独立的无论您是否将同一种语言称为“脚本语言”,(以及无数其他事情)。最重要的是,它也是一个破碎的分类:
你看,现实是一头复杂的野兽;)如上所述,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:
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.
是的。
详细响应:
脚本语言通常用于控制通常不是用该语言编写的应用程序。例如,shell脚本等可以调用任意控制台应用程序。
Ruby 是一种通用动态语言,经常用于脚本编写。
您可以使用反引号表示法进行任意系统调用,如下所示。
还有许多优秀的 Ruby gem,例如 Watir 和 RAutomation 用于自动化 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.
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.
“脚本语言”这个术语非常广泛,它可以包括解释型语言和编译型语言。特别是 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.