开发者

Is Ruby a scripting language or an interpreted language?

开发者 https://www.devze.com 2023-04-02 14:53 出处:网络
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 dif

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 a开发者_StackOverflownd forgive me for the black out


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.


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.


The term 'scripting language' is very broad, and it can include both interpreted and compiled languages. Ruby in particular, might 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

0

精彩评论

暂无评论...
验证码 换一张
取 消