Ruby goodies?

Im a C# programmer and Im totally new to Ruby.

What would you guys say is the main benefits of Ruby over C#?
C# has closures and is getting lambdas in C#3

So in what scenarios should I absolutely go for Ruby instead of C#?

One of the benefits that I’ve found myself is the reflection/runtime
modification support.

When I implemented my .NET AOP lib NAspect in .NET it took a few good
months to make it work.

In Ruby it took me about 5h to get support for pointcuts, interceptors
and the whole kit.
So that part was pretty amazing.

but are there any other areas where ruby really shines, or are all of
the goodies related to the abillity to modify things on the fly?

//Roger

On Thu, Jun 22, 2006 at 08:44:28PM +0900, Roger J. wrote:

[…]
but are there any other areas where ruby really shines, or are all of
the goodies related to the abillity to modify things on the fly?

I would say blocks. But not exactly that they're _available_ (they 

have
been basically available in lots of languages for years), but the way
they’re
integrated into the language and the stdlib, and them being so easy and
natural to use.

Probably other things, but blocks is the first thing that came to my 

mind.

2006/6/22, [email protected] [email protected]:

excellent list all of which I completely agree

What I also like is that it’s OO is so clean and easy that I end up
creating classes all the time - even for simple scripts. Often that
involves just MyClass = Struct.new(:foo, :name; :bar) and I can
immediately use MyClass instances as Hash keys etc. In Perl, for
example, I’d probably end up using arrays all the time because
creating classes is so tedious and error prone (at least it was the
last time I tried).

Also, Hash is very powerful - especially considering the form with the
block for missing elements. It makes many scripts very easy.

collect = Hash.new {|h, k| h[k] = []}

don’t worry about non existing keys here:

collect[my_key] << something

And then there are all those nifty details, e.g. String, IO and Array
implement << so you can pass any of these to a method that “appends”
something and it will work. There’s a lot of these convenient things
in Ruby.

Kind regards

robert

I think the way to answer your question is by examples of what has been
built in Ruby:

  • Erb – It’s a very simple text/HTML markup system that has most of
    the features of ASP.Net and gets the benefits of Java tag libraries
    without anything other than the syntax of Ruby.
  • ActiveRecord – Ruby’s philosophy has allowed for a light-weight,
    very powerful, very flexible OR mapping system without code
    generation or
    the other stuff that comes along with OR mapping in .Net or Java.
  • Writing tests – look at the tests that are part of Ruby
    projects…
    they’re far expressive and syntactically simple than anything I’ve
    seen in
    C#.
  • OS integration – Ruby is better integrated in the OS and with C
    code than .Net will ever be. Even though .Net allows near-seamless
    integration with COM objects and calls in the C code, in the
    practical
    world, there’s always a hidden ‘gotcha’ that causes 30 hours of QA to
    reproduce and 20 hours of development time to fix.
  • Rails – If Microsoft could have developed something as simple and
    powerful as Rails, they’d own the world. Instead, the Ruby gestault
    allowed
    a small, very smart bunch of folks to roll 75%+ of the mundane web
    development chores into an amazing package that doesn’t generate a
    single
    line of code.

C# has its roots in C++ (as does Java.) There are benefits to those
roots.
There are also costs to those roots. Ruby has its roots in (among other
things) SmallTalk. Out of SmallTalk’s gestault grew OS X’s
InterfaceBuild
and Rails, two of the most beautiful development environments.

It’s not about features on a checklist, it’s about the approach that
Ruby
allows to solving problems.

Thanks,

David

Roger J. wrote:

What would you guys say is the main benefits of Ruby over C#?

One obvious thing that hasn’t been mentioned is broad cross platform
support. Mono helps, but most C# development I’ve seen has been windows
only.

-Brian

Hi –

On Thu, 22 Jun 2006, James B. wrote:

[email protected] wrote:

Perhaps above all, the clean, expressive syntax. There’s relatively
little punctuation; well-written Ruby code has a sparse look that I,
and a lot of other people, love, and it manages to be terse without
being cryptic. (Badly-written or [Java/C/Perl/…]-like Ruby code,
does not have these qualities :slight_smile:

I see Ruby code as being succinct rather than terse. Perhaps a minor
distinction, but in my mind ‘terse’ has a pejorative quality.

I think you’re right. Terse does evoke abruptness and anger and
stuff. Succinct, concise, expressive are better descriptions.

I’ll stick with “without being cryptic” though :slight_smile:

David


David A. Black ([email protected])
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

See what the readers are saying about “Ruby for Rails”!

[email protected] wrote:

Hi –

On Thu, 22 Jun 2006, Roger J. wrote:

Perhaps above all, the clean, expressive syntax. There’s relatively
little punctuation; well-written Ruby code has a sparse look that I,
and a lot of other people, love, and it manages to be terse without
being cryptic. (Badly-written or [Java/C/Perl/…]-like Ruby code,
does not have these qualities :slight_smile:

I see Ruby code as being succinct rather than terse. Perhaps a minor
distinction, but in my mind ‘terse’ has a pejorative quality.

Well-written Ruby code seems to flow more naturally. The combination of
open classes and blocks offers remarkable options for expressiveness.

Jamis B. wrote a very good article[0] on integration testing in Rails
that nicely shows how one can evolve from good but codey tests to what
comes close to being executable narratives.

[0]
http://jamis.jamisbuck.org/articles/2006/03/09/integration-testing-in-rails-1-1


James B.

“In physics the truth is rarely perfectly clear, and that is certainly
universally the case in human affairs. Hence, what is not surrounded
by
uncertainty cannot be the truth.”

  • R. Feynman

Hi.

I’ve had similar feeling recently and tried to translate what I can do
in
Ruby
into Java. And it turns out that data structure facility in this
language is
very much powerful.

Consider:
list = [1,2,3,4,5] # How would you do this list creation in C#?
list = { 1=> ‘a’, 2=> ‘b’ } # How could you initiate a hash with these
default values?

You’ll find that such a simple initialization turns out to be
complicated in
C# and/or Java.

Also, consider:
(1…100).to_a.min # This returns 1 which is the smallest number between
1 to
100.
Do you think it would be possible to write such a succint code in C#?

Not only metaprogramming facility - which is awesome btw - but also data
structures
are playing crucial role in this language.

Sincerely,
Minkoo S.

What would you guys say is the main benefits of Ruby over C#?

John L. has a great video on “The Future of Programming Languages”
here:

http://www.ftponline.com/channels/net/reports/vsliveto/2006/multimedia/lam.aspx

in which he shows a number of cases where Ruby is much simpler and
more elegant than the equivalent C# code.

(You’ll need to login to watch the video. You can get a login from
www.bugmenot.com)

Wayne


Wayne V.
No Bugs Software
Ruby and C# Agile Contract Programming in Silicon Valley

Hi –

On Thu, 22 Jun 2006, Roger J. wrote:

When I implemented my .NET AOP lib NAspect in .NET it took a few good
months to make it work.

In Ruby it took me about 5h to get support for pointcuts, interceptors
and the whole kit.
So that part was pretty amazing.

but are there any other areas where ruby really shines, or are all of
the goodies related to the abillity to modify things on the fly?

Definitely the former. But I can’t enumerate things about Ruby that
you’re going to like; you have to try it out, and see whether it
speaks to you.

I can, however, enumerate some things that I like :slight_smile:

Perhaps above all, the clean, expressive syntax. There’s relatively
little punctuation; well-written Ruby code has a sparse look that I,
and a lot of other people, love, and it manages to be terse without
being cryptic. (Badly-written or [Java/C/Perl/…]-like Ruby code,
does not have these qualities :slight_smile:

I also like the code block/iterator facility, whereby a method call
can include a code block as well as an argument list. And I like
‘yield’. I know there’s a vogue for doing:

def meth(a,b,c,&block)
&block.call

instead of using yield, but I find that yield gives me more of a sense
of a kind of hand-off to the code block, and therefore puts weight on
the code block as a syntactic construct in a way that make sense.

I love the way Ruby builds on simple principles, and has a kind of
mid-level range of “features” that are actually not language-level but
can sort of masquerade as language-level for the benefit of people who
want them. This happens already with class methods and attributes,
both of which are things that people seem to expect, and which can be
layered on top of the design of Ruby very easily without adding
anything at the language level.

One of the things that intrigues me about Ruby is whether there are
cases where some previously unheard-of features could be implemented
this way. In other words, if Ruby is so good at whipping up class
methods from the singleton method architecture, and attributes from a
mixture of instance variables and methods, what else might be whipped
up, including things that are not expressions of traditional OO
programming components?

This is also why I tend to react negatively to most suggestions that
involve fixing this kind of feature permanently and irrevocably in the
language.

Anyway, that’s a few early AM thoughts, as I prepare to leave my hotel
room and help run the first official International Rails Conference.
There are, or will be, 550 Rails developers here – and more
conferences and user group meetings and publications and chat of every
conceivable sort to come in the coming weeks, months, and years. And
that is what I really love about Ruby.

David


David A. Black ([email protected])
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

See what the readers are saying about “Ruby for Rails”!

On 6/24/06, Minkoo S. [email protected] wrote:

Also, consider:
(1…100).to_a.min # This returns 1 which is the smallest number between 1
to
100.

(1…100).min also works, becasue this is defined in Enumerable.

j`ey
http://www.eachmapinject.com