Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I just finished reading the Ruby chapter of the book 7 Languages in 7 Weeks. Aside from some syntactic sugar here and there I can't really see anything which can't be done with C# with a similar syntax. I do understand both languages are inherently different, but my question relates to its usage rather than design.

Relevant questions make me believe Ruby offers little more than C#:

I hardly worked with Ruby and my understanding of the language is still very limited, so perhaps somebody who experimented with both .NET 4.0 and Ruby can answer with concrete examples.

Which tasks require significantly less work with Ruby than C# 4.0?

P.s.: This question got closed on StackOverflow as too subjective and argumentative, although it did attract some attention. I was hoping it would be merged to here, but instead I'll just have to repost it.

share|improve this question
1  
Would compiling be one of them? –  Andrew Grimm Apr 28 '11 at 0:21
    
I'd be interested in this question, as I assume C# is faster and has a larger community than Ruby. –  Andrew Grimm Apr 28 '11 at 0:21

1 Answer 1

up vote 7 down vote accepted

Ruby has literals for Regular Expressions and a bunch of useful syntactic shortcuts for the creation/interpolation of strings. So when your task(s) are primarily related to mixing an matching bits and pieces of strings Ruby might require significant less work (but outside of short helper scripts I must admit I found this to be a very rare situation).

More relevant are Ruby's meta-programming facilities. i.e. #eval, #define_method and friends, which combined with open classes, #include and #extend allow you to create tons of boilerplate code at runtime - you can argue, that code generators/wizards give you some of the same benefits, but you have to live with the - possibly very large amounts - of generated boiler plate code, compared to a relatively small amount of meta-programming code you'd have to read and understand.

A typical use cases for this is, having to interface with some kind of dynamic data provider outside of your application. Rails ActiveRecord is a good example for that.

In the future this might be very beneficial for developing GUIs, as you can generate methods handling events from user interface elements by creating methods during runtime based upon the UI elements ID, type, input values etc. (like Objective-C on steroids, maybe we'll see some of this power when MacRuby matures).

The line between good use and horrible abuse of this feature though is very very thin, and tends - from my experience - to be a major cause for headaches in large Ruby (on Rails) projects. So be careful when you decide to release the Djinn from it's bottle :)

share|improve this answer
    
Nice answer! Easier string manipulation makes sense, Ruby on Rails being a web framework I guess. I would have to compare metaprogramming once to see whether a certain goal can be accomplished easier in Ruby than in C#. If you would happen to have an interesting concrete (not too big) example that would be nice. ;p –  Steven Jeuris Apr 28 '11 at 11:49
    
As said, the ActiveRecord library/framework is a concrete example. –  Alexander Battisti Apr 28 '11 at 11:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.