why ruby ?

why we use ruby rather than other language.

Santosh wrote:

why we use ruby rather than other language.

Because Ruby has many features that make it extraordinarily flexible and easy to program. Most people who use it cannot remember working with any language so easy.

If someone wrote a Rails-style web framework in any other language, it might have any of these problems...

- a big corporation invented the language and made it
      stupid and obese on purpose

- no support for block closures, which allow very
      minimal code to get a lot done

- poor support for OO. The best Object Oriented
      programming makes everything an object, even a 5

- no rabid community of people competing with each
      other to add cool features to many projects

- a code line count from 3 times to 20 times greater

Put them all together, and "Ruby stays out of your way". You can write only a little Ruby and get a lot done. Try this:


If you had to use any other language, you could write 2 to 5 times as much code just to calculate 3 seconds before the current time. That might make you hesitate, and then might make you chose a less obvious strategy, such as entering a fixed date and changing other code to accomodate it.

Ruby often lets you express yourself with lines that read like normal English. So as you refactor and clean up your code, pushing it towards normal English will often make the code leaner and simpler. Other languages don't permit such incredible flexibility and expressiveness. Here's an example from one of the books:

  Order has_many :line_times

That's within a few delimiters of gramatically correct English. And it replaces a couple dozen lines of ugly SQL.

Short answer: you write less code.

Long answer:


Ruby is a wonderfully expressive langugage. My personal experience is
that I can express the same idea in about a tenth to a quarter of the
lines of code that I would need in Java.

While lines of code are a terrible metric for progress, they are a
good metric for complexity and stability:

It has been shown empirically that a programmer will write about the
same amount of lines of code in a day, regardless of the language he

Every line of code that is written contains at least two points where
faults can be introduced:
1. an algorithmic fault - the idea itself, which is expressed in the
line of code, is wrong
2. a syntactic fault - the way in which the idea is expressed is wrong

If a ruby programmer writes less code, the opportunities to make
mistakes are dramatically reduced, specifically those of the syntactic

Another interpretation is that of essential and accidental complexity:

Essential complexity describes the complexity inherent in a problem,
for example the minimum number of operations required to execute a
bubblesort algorithm.

Accidental complexity describes the complexity required to satisfy a
framework or a programming language, for example the need for static
typing in Java or the horrible mess that is the J2EE standard.

By reducing accidental complexity through a concise language like Ruby
and a framework like Rails, you instead concentrate on the essential

While I can write very concise code in Perl, it looks rather like a
cat ran over the keyboard. One of the major points for Ruby is that it
does not sacrifice readability for conciseness. Keep in mind that
while a line of code is written only once, it is read many times
(either by you, or by some other person tasked with maintaining it).


Sensible defaults (convention over configuration) - if a feature is
used by 100 people in 99 different ways, the one way that is used by
two people should be the default. While extensibility and flexibility
is a worthwhile goal for the development of frameworks, it can
eventually lead to the problems that the J2EE standard has -
everything (and I mean *everything*) must first be configured in some
extremely verbose configuration language. Why a framework would force
me to do that rather than give me the behaviour desired by 90% of its
users is simply beyond me.

DRY - Rails is the best example I know of the very consistent
application of some important design principles, most notably "Don't
Repeat Yourself". I find that when writing Rails code, I cringe every
time I copy and paste a piece of code. This is because I know that
there are easy-to-use mechanisms in the framework that allow me to
refactor the common parts of the code in very little time. The
benefits of working in a framework that causes that kind of attitude
in a programmer cannot be overstated.

In summary, using Ruby and Rails gives me significant productivity
gains - I was sceptical when I first read about those gains stated by
other people, but I have found them confirmed, and then some. If I am
writing less code to express the same ideas, I get more ideas
implemented in a shorter amount of time. This is not only extremely
satisfying, it also serves - at least for me - as a great motivator as
I can see more visible progress in my projects.


It’s the wrong question. It should be: Why would you program in any other language rather than in Ruby?


for the purposes of this list, i'd go with "because you want to use rails". it's rather impossible to use rails without ruby. there are other reasons, but probably better asked and answered in other contexts.


Max Muermann wrote: