Advantages of Ruby

I am new to Ruby. I have done most of my development in statically
typed languages (Java, C++, C#, etc.).

I understand that there are advantages and disadvantages to dynamic
versus static typing. What idioms/patterns can you do in Ruby that you
just can't do in statically typed languages? Are there problems you can
solve in Ruby that you can't solve or would be awkward to solve in
statically typed languages?

Is there a website or document that describes this somewhere?

[Note: I'm not interested in starting any language wars here. I really
want to understand the expressive advantages of Ruby.]

Thanks!

PDF::Writer is 6,000 lines of code. Readable code. I suspect that
other implementations are much larger.

-austin

···

On 10/19/05, rjack@elegancetech.com <rjack@elegancetech.com> wrote:

I am new to Ruby. I have done most of my development in statically
typed languages (Java, C++, C#, etc.).

I understand that there are advantages and disadvantages to dynamic
versus static typing. What idioms/patterns can you do in Ruby that you
just can't do in statically typed languages? Are there problems you can
solve in Ruby that you can't solve or would be awkward to solve in
statically typed languages?

Is there a website or document that describes this somewhere?

[Note: I'm not interested in starting any language wars here. I really
want to understand the expressive advantages of Ruby.]

--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

rjack@elegancetech.com wrote:

I am new to Ruby. I have done most of my development in statically
typed languages (Java, C++, C#, etc.).

I understand that there are advantages and disadvantages to dynamic
versus static typing. What idioms/patterns can you do in Ruby that you
just can't do in statically typed languages?

One of the major advantages is that you get polymorphism without the need
to make types compatible (via a common interface like in Java for
example). In Ruby you can easily do something like this:

f = lambda {|x| puts "calc...";x ** x}
if do_it_fast?
  calc = Hash.new do |h,k|
    h[k] = f[k]
  end
else
  calc = f
end

puts calc[10]
puts calc[10]

i.e. you can use a Hash and a lambda interchangably. Basically, you gain
a lot of flexibility.

Are there problems you
can solve in Ruby that you can't solve or would be awkward to solve in
statically typed languages?

I don't think this is about issues not being solvable but about needing
more or less lines of code (which directly impacts productivity and
likeliness of bugs).

Kind regards

    robert

I recently rewrote a C++ library in Ruby. The Ruby version is smaller
by a factor of 11, despite having all the same functionality.

And the Ruby version is well-covered with unit tests, something I
never had in the C++ version. If you count the unit test code as part
of the library, it's still 8x smaller.

That's approximately 8x fewer bugs, 8x faster development, and 8x
lower maintenance cost. Smaller code is better code. Choosing a more
expressive language is the best way to make your code smaller.

Computer languages fall on a continuum that moves from low-level,
hardware-oriented code up toward more abstract, human-oriented code.
A rough ordering, IMHO, goes like this:

assembly
C
C++
Java
Python
Perl,Ruby
Haskell
Lisp

I choose Ruby over Java for the same reason you choose Java over C.
In general it's a mistake not to use the most powerful language you
realistically have available.

Why don't more people use the really high level languages? Mostly
because languages are not only tools, but also habits of thought. And
habits of thought evolve very slowly.

regards,
Ed

···

On Wed, Oct 19, 2005 at 11:21:58PM +0900, rjack@elegancetech.com wrote:

I understand that there are advantages and disadvantages to dynamic
versus static typing.

Edward Faulkner <ef@alum.mit.edu> writes:

Computer languages fall on a continuum that moves from low-level,
hardware-oriented code up toward more abstract, human-oriented code.
A rough ordering, IMHO, goes like this:

assembly
C
C++
Java
Python
Perl,Ruby
Haskell
Lisp

Getting off-topic, but this is a vast misjudgement of Lisp. Lisp
allows you to program in every layer, be it low-level code (where it
is nothing less than a good macro-assembler) or even microcode up to
state-of-the-art, distributed objected-oriented systems.

Remember that the Lisp machines were programmed in Lisp down to the
core. (Heck, some even had a C compiler written in it...)

Why don't more people use the really high level languages? Mostly
because languages are not only tools, but also habits of thought. And
habits of thought evolve very slowly.

Full ack. :-/

···

regards,
Ed

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org