Several reasons:

  • faster development loop, write-test vs write-compile-link-test
  • easier to arrange for dynamic behavior (reflection, metaprogramming)
  • makes the whole system portable (just recompile the underlying C code and you are good to go on a new platform)

Think of what would happen if the system was not interpreted. Say you used translation-to-C as the mechanism. The compiled code would periodically have to check if it had been superseded by metaprogramming. A similar situation arises with eval()-type functions. In those cases, it would have to run the compiler again, an outrageously slow process, or it would have to also have the interpreter around at run-time anyway.

The only alternative here is a JIT compiler. These systems are highly complex and sophisticated and have even bigger run-time footprints than all the other alternatives. They start up very slowly, making them impractical for scripting. Ever seen a Java script? I haven't.

So, you have two choices:

  • all the disadvantages of both a compiler and an interpreter
  • just the disadvantages of an interpreter

It's not surprising that generally the primary implementation just goes with the second choice. It's quite possible that some day we may see secondary implementations like compilers appearing. Ruby 1.9 and Python have bytecode VM's; those are ½-way there. A compiler might target just non-dynamic code, or it might have various levels of language support declarable as options. But since such a thing can't be the primary implementation, it represents a lot of work for a very marginal benefit. Ruby already has 200,000 lines of C in it...

I suppose I should add that one can always add a compiled C (or, with some effort, any other language) extension. So, say you have a slow numerical operation. If you add, say Array#newOp with a C implementation then you get the speedup, the program stays in Ruby (or whatever) and your environment gets a new instance method. Everybody wins! So this reduces the need for a problematic secondary implementation.

Answer from DigitalRoss on Stack Overflow
Top answer
1 of 12
32

Several reasons:

  • faster development loop, write-test vs write-compile-link-test
  • easier to arrange for dynamic behavior (reflection, metaprogramming)
  • makes the whole system portable (just recompile the underlying C code and you are good to go on a new platform)

Think of what would happen if the system was not interpreted. Say you used translation-to-C as the mechanism. The compiled code would periodically have to check if it had been superseded by metaprogramming. A similar situation arises with eval()-type functions. In those cases, it would have to run the compiler again, an outrageously slow process, or it would have to also have the interpreter around at run-time anyway.

The only alternative here is a JIT compiler. These systems are highly complex and sophisticated and have even bigger run-time footprints than all the other alternatives. They start up very slowly, making them impractical for scripting. Ever seen a Java script? I haven't.

So, you have two choices:

  • all the disadvantages of both a compiler and an interpreter
  • just the disadvantages of an interpreter

It's not surprising that generally the primary implementation just goes with the second choice. It's quite possible that some day we may see secondary implementations like compilers appearing. Ruby 1.9 and Python have bytecode VM's; those are ½-way there. A compiler might target just non-dynamic code, or it might have various levels of language support declarable as options. But since such a thing can't be the primary implementation, it represents a lot of work for a very marginal benefit. Ruby already has 200,000 lines of C in it...

I suppose I should add that one can always add a compiled C (or, with some effort, any other language) extension. So, say you have a slow numerical operation. If you add, say Array#newOp with a C implementation then you get the speedup, the program stays in Ruby (or whatever) and your environment gets a new instance method. Everybody wins! So this reduces the need for a problematic secondary implementation.

2 of 12
16

Exactly like (in the typical implementation of) Java or C#, Python gets first compiled into some form of bytecode, depending on the implementation (CPython uses a specialized form of its own, Jython uses JVM just like a typical Java, IronPython uses CLR just like a typical C#, and so forth) -- that bytecode then gets further processed for execution by a virtual machine (AKA interpreter), which may also generate machine code "just in time" -- known as JIT -- if and when warranted (CLR and JVM implementations often do, CPython's own virtual machine typically doesn't but can be made to do so e.g. with psyco or Unladen Swallow).

JIT may pay for itself for sufficiently long-running programs (if memory's way cheaper than CPU cycles), but it may not (due to slower startup times and larger memory footprint), especially when the types also have to be inferred or specialized as part of the code generation. Generating machine code without type inference or specialization is easy if that's what you want, e.g. freeze does it for you, but it really doesn't present the advantages that "machine code fetishists" attribute to it. E.g., you get an executable binary of 1.5 to 2 MB in lieu of a tiny "hello world" .pyc -- not much point!-). That executable is stand-alone and distributable as such, but it will only work on a very specific narrow range of operating systems and CPU architectures, so the tradeoffs are quite iffy in most cases. And, the time it takes to prepare the executable is quite long indeed, so it would be a crazy choice to make that mode of operation the default one.

Top answer
1 of 3
50

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.

2 of 3
5

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.

Discussions

Are Python, PHP, JavaScript, Perl & Ruby Classed As Scripting Languages?
What does it mean to be a scripting language? If you just mean interpreted, then sure, but by that definition, so is Java. More on reddit.com
🌐 r/learnprogramming
12
7
December 15, 2014
Why is Ruby so much used in startup/scale-up over other languages?
Because its "batteries included" You can get a lot for "free" by going with Ruby (and Rails). The language is nice, Rails does a ton, and its still possible to hire for fairly easily. Big full frameworks like Rails are actually fairly rare, if you look at the entire ecosystem of other frameworks. You basically only have Django and Rails, with Phoenix offering many (but not all) of the same features. Most "frameworks" out there are closer to Sinatra, where you get some useful primitives for building a web application, but not much more than that. Take a look at Express.js. You have everything you need, but in terms of direction or convention, you're on your own. In terms fo the language itself, Ruby is pretty great. Its ergonomics make it easy to write, and easy to reason about. The biggest pitfalls Ruby faces are faced by many other languages, unless they explicitly went out of their way to avoid them (Elixir, for example, made conscious choices to avoid some ruby-like pitfalls, that limit some of its flexibility, but remove a footgun) More on reddit.com
🌐 r/ruby
104
57
December 7, 2023
interpreter - Is Ruby really an interpreted language if all of its implementations are compiled into bytecode? - Stack Overflow
I think you're right to question the utility of characterizing languages as "compiled" vs. "interpreted." One useful distinction, though, is whether the language creates machine code (e.g. x86 assembler) directly from user code. C, C++, many Lisps, and Java with JIT enabled do, but Ruby, Python, ... More on stackoverflow.com
🌐 stackoverflow.com
What language features, if any, give JS a performance advantage over Python and Ruby?
From what I understand, JS is notoriously difficult to optimize. I am not sure however that JS and Python for example are that fundamentally different. Member lookup in both is implemented rather similarly: by walking a chain of linked tables (with possibility to customize it). I believe that if given comparable funding, equally performant JITs can be created for both languages . Another scripting language, Lua, has an incredibly performant tracing JIT (LuaJIT), written by a single person. The author of LiaJIT stated it was only possible for him to do because of Lua's simplicity. More on reddit.com
🌐 r/ProgrammingLanguages
73
32
May 7, 2020
People also ask

What is an interpreted language?

An interpreted language is a programming language that executes instructions directly, without the need for a separate compilation step. The instructions are translated and executed line by line, making it easier and quicker to develop and test code.

🌐
lenovo.com
lenovo.com › home
An Introduction to the World of Interpreted Languages | Lenovo US
Which programming languages are commonly interpreted?

Some popular interpreted languages include Python, JavaScript, Ruby, Perl, and PHP. These languages are widely used in web development, scripting, and automation tasks due to their ease of use and quick development process.

🌐
lenovo.com
lenovo.com › home
An Introduction to the World of Interpreted Languages | Lenovo US
How does an interpreted language differ from a compiled language?

In an interpreted language, the code is executed line by line, while in a compiled language, the entire code is converted into machine language before execution. This means that interpreted languages offer more flexibility in terms of modifying and testing code on the fly.

🌐
lenovo.com
lenovo.com › home
An Introduction to the World of Interpreted Languages | Lenovo US
🌐
Quora
quora.com › Are-Ruby-JavaScript-and-Python-all-interpreted-languages
Are Ruby JavaScript and Python all interpreted languages? - Quora
Answer (1 of 4): First of all, languages themselves are not interpreted or compiled; their implementations are. A programming language is just a piece of paper describing what is and isn’t a valid program, and what is the expected semantics. With this out of the way, for both Ruby and Python, ...
🌐
Reddit
reddit.com › r/learnprogramming › are python, php, javascript, perl & ruby classed as scripting languages?
r/learnprogramming on Reddit: Are Python, PHP, JavaScript, Perl & Ruby Classed As Scripting Languages?
December 15, 2014 - Some people will instead argue that a scripting language is any language which is run via an interpreter. Python, PHP, Ruby, Perl, and Javascript are all commonly run through interpreters, whereas languages like C, Java, and C# are commonly not.
Find elsewhere
🌐
DEV Community
dev.to › szam › ruby-vs-python-vs-c-vs-javascript-h56
Ruby VS Python VS C++ VS JavaScript - DEV Community
December 1, 2021 - JavaScript definitely surprised me the most with how speedy quick it was, and I didn't think Python would be as slow as it was. It might have something to do with including that random module (I had to change the name of the file to rand because the interpreter didn't like the file having the same name as the module). Ultimately I know every programming language has its pros and cons and obviously generating a random number isn't the best benchmark for a language.
🌐
Lenovo
lenovo.com › home
An Introduction to the World of Interpreted Languages | Lenovo US
Some popular interpreted languages include Python, JavaScript, Ruby, Perl, and PHP.
🌐
Medium
medium.com › @anirbanroydas › python-ruby-node-go-java-scala-javascript-the-language-cocktail-its-mystical-nature-be598e266a2b
Python, Ruby, Node, Go, Java, Scala, Javascript - the language cocktail & its mystical nature | by ANIRBAN ROY DAS | Medium
April 12, 2017 - All these are different for different languages. More, the way profiling is done, the way debugging is done, the flexibility of variable assignments, the nature of the type definition, assignments, some are statically typed like C/C++, Java, Go, some are dynamically typed like python, ruby, javascript, php.
🌐
Ironhack
ironhack.com › us › blog › javascript-vs-ruby-which-coding-language-should-you-learn
JavaScript vs Ruby: Which Coding Language Should You Learn?
May 28, 2023 - But if you’re asking what language you should learn next, you’re probably trying to expand your skill set to be able to take on different tasks. If that’s the case, consider learning Python, Java, C, or (you guessed it!) Ruby. Python is very similar to JavaScript in the sense that it’s also an interpreted...
🌐
Reddit
reddit.com › r/ruby › why is ruby so much used in startup/scale-up over other languages?
r/ruby on Reddit: Why is Ruby so much used in startup/scale-up over other languages?
December 7, 2023 -

Hi people,

I'm coming from the world of Java / Kotlin web applications, I'm starting getting curious about other languages that are really liked among big companies.

I am a total beginner and I don't understand why a company would go for Ruby instead of another interpreted languages such as Python or JavaScript stack.

Although I totally understand that bootstrapping a MVP with Ruby is soooo easy, it feels to me that maintaining a code base with hundreds of files, a big domain, a lot of tests, ... is very hard with it (so it is with python).

Can you explain me like I'm 5 why companies are going for Ruby. If you remove the "because the first dev only knew Ruby so he bootrapped very fast, we were in PRD and then we continued building over his code" reason, what is left for Ruby?

TLDR: I don't won't to be offensive, I would just like to talk with Ruby senior programmers to understand that hype, the salariés, why all of this is that justified? How is it to maintain ruby codebase, ok it's easy to have a easy CRUD blog app with article and commente, but what about a whole marketplace?

Thanks :)

EDIT: Thanks to all of you for your answers, you rock!

Top answer
1 of 37
47
Because its "batteries included" You can get a lot for "free" by going with Ruby (and Rails). The language is nice, Rails does a ton, and its still possible to hire for fairly easily. Big full frameworks like Rails are actually fairly rare, if you look at the entire ecosystem of other frameworks. You basically only have Django and Rails, with Phoenix offering many (but not all) of the same features. Most "frameworks" out there are closer to Sinatra, where you get some useful primitives for building a web application, but not much more than that. Take a look at Express.js. You have everything you need, but in terms of direction or convention, you're on your own. In terms fo the language itself, Ruby is pretty great. Its ergonomics make it easy to write, and easy to reason about. The biggest pitfalls Ruby faces are faced by many other languages, unless they explicitly went out of their way to avoid them (Elixir, for example, made conscious choices to avoid some ruby-like pitfalls, that limit some of its flexibility, but remove a footgun)
2 of 37
44
People use it because it's a great language that gets out of your way. It's a joy to work in compared to things like Java. If ruby had decent parallel processing and proper async I'd never use a different language. it feels to me that maintaining a code base with hundreds of files, a big domain, a lot of tests, ... is very hard with it (so it is with python). Do you honestly think that maintaining a large java project with hundreds of files and lots of tests is easy? I'm trying to understand why it would be harder aside from the fact that you have experience doing it in Java but not Ruby.
🌐
Codecademy
codecademy.com › forum_questions › 526d818cf10c606a04000977
Experts: What are the differences between Ruby, Python, Javascript & PHP? | Codecademy
For instance, all of the mentioned languages are interpreted, meaning they are not compiled prior to run time. They all rely upon one form or another of try and catch to trap inconsistencies that would otherwise throw an error and halt the program. They all rely on a generic set of flow control constructs, such as conditionals and loops.
🌐
Fermyon
fermyon.com › blog › scripts-vs-compiled-wasm
Scripting Languages and Compiled Languages in WebAssembly
March 7, 2022 - Five scripting languages made the top ten programming languages list: JavaScript (#1), Python (#2), PHP (#4), TypeScript (#8), and Ruby (#9). Scripting languages are typically not compiled.
🌐
Medium
medium.com › @jyang81 › why-is-it-called-ruby-javascript-python-89c1141717a3
Why is it called Ruby/JavaScript/Python? | by Joe Yang | Medium
April 17, 2019 - They renamed it LiveScript, then JavaScript, which confused a lot of people, making them think it was a spin-off of Java. The founder said it was a marketing ploy to associate it as a “side-kick language” for demo purposes, which he said he regrets. The demo went live, and the name stuck. So, it does kind of have to do with coffee, but not really. So I just assumed that Python had something to do with a snake (it does use snake_case), but I was way off.
🌐
Quora
quora.com › Are-Ruby-Python-and-JavaScript-all-similar-in-that-they-compile-to-C
Are Ruby, Python and JavaScript all similar in that they compile to C? - Quora
Answer (1 of 4): The languages are just syntax and semantics; there are reference implementations and alternate ones for each on various platforms. But a language is not compiled or interpreted it is a language. The compiler or interpreter is just a program that translates that language somehow.
🌐
Stanford University
web.stanford.edu › class › cs98si › slides › overview
Introduction
JavaScript’s syntax is heavily inspired by C++ and Java. If you have experience in C++ or Java, JavaScript’s syntax will seem familiar to you. However, the inner workings of JavaScript is closer to a dynamically-typed, interpreted language such as Python or Ruby.
🌐
Study.com
study.com › computer science › computer programming › programming languages
Interpreted Languages | Study.com
An interpreted language executes code line by line through an interpreter without requiring prior compilation to machine code. These languages, including Python, JavaScript, and Ruby, offer advantages like cross-platform compatibility, faster ...
🌐
Reddit
reddit.com › r/programminglanguages › what language features, if any, give js a performance advantage over python and ruby?
r/ProgrammingLanguages on Reddit: What language features, if any, give JS a performance advantage over Python and Ruby?
May 7, 2020 -

Hi all – Are there aspects of Python and Ruby as languages that prevent them from being optimized to the extent that JavaScript has?

Different way to ask this question: If you had a $75 million budget, could you produce a Python or Ruby JIT that was as performant as Chromium's V8 JIT or Microsoft's Chakra? (You could for example pay 75 elite developers $333,333 per year for three years...)

I ask in part because Python and Ruby have had maybe 15 years to match JS runtime performance, and they haven't done so. Sometimes people make the argument that JS got fast because of economics – that Google, Microsoft, Apple, and Mozilla threw a lot of money at JS JIT development. But Python and Ruby are huge open source projects, and my expectation would be that such projects have plenty of talented developers and should in principle be able to match commercial performance, eventually...

Are there language features that give a performance advantage to JavaScript, or disadvantage Python and Ruby?

Yes, I'm aware of: PyPy and the new JIT in Ruby/mruby 2.6 or 2.7. Neither seems to approach V8 or Chakra performance. PyPy is impressive though (but it only supports older versions of Python, not 3.7 or 3.8). I'm also aware of Unladen Swallow, an aborted effort toward an LLVM-based JIT for Python. That was a couple of young developers, which is partly why I asked the $75 million budget question. And jruby.

Thanks.

Top answer
1 of 16
49
Sometimes people make the argument that JS got fast because of economics – that Google, Microsoft, Apple, and Mozilla threw a lot of money at JS JIT development. I don't really get why you dismiss this aspect so quickly. If you want more capabilities in the browser and better experience for end users there has only been one way: make Javascript execution faster. With Python and Ruby you can write modules in any language, which can provide headers (?) like C. Python doesn't have to be fast. With Javascript there simply was no other option. However, it is a good question. I don't really know enough about the details to give an answer, though. Edit: Note, I don't answer OPs question. I just give some additional context for why the "economics" is a fairly good reason why Javascript is so fast. Please, read the rest of the thread and the excellent posts wrt. why it can and can't be done.
2 of 16
23
From what I understand, JS is notoriously difficult to optimize. I am not sure however that JS and Python for example are that fundamentally different. Member lookup in both is implemented rather similarly: by walking a chain of linked tables (with possibility to customize it). I believe that if given comparable funding, equally performant JITs can be created for both languages . Another scripting language, Lua, has an incredibly performant tracing JIT (LuaJIT), written by a single person. The author of LiaJIT stated it was only possible for him to do because of Lua's simplicity.