I am giving a series of talks to a .NET (C#) development team on the Ruby language and environment. I am approaching it as an opportunity to highlight the benefits of Ruby over C#. At first, I want to concentrate on the language itself before moving into the environment (RoR vs ASP MVC, etc). What features of the Ruby language would you cover?
Mix ins and multiple inheritance.
Its dangerous in the wrong hands, but quite beneficial for proper encapsulation of things, as opposed to having to inherit lots of things you don't necessarily need.
Duck Typing! This will be less of an issue in c# 4.0, but there have been times when I had to duplicate whole blocks of code because two related classes with (for my purposes) identical APIs did not share a base class.
Also, blocks. C# has lambdas, but Ruby's syntax is prettier and they are used pervasively throughout the standard libraries. They are much more a part of idiomatic Ruby than idiomatic c#, and that counts for something.
Edit
Hash literals deserve a mention, too. In general I'd emphasize how concise you can be in Ruby, and how this allows you to express intent better and spend less time trying to make the compiler happy
I gave a talk to a .NET user group a while ago about IronRuby, and faced similar problems. The things I focused on were:
Duck typing. There's nothing stupider than
List<string> stringList = new List<string>()
;Expressive and Concise syntax. Simple things like leaving out parentheses, array and hash literals, etc. (combined with duck typing, you get
string_list = []
which is obviously nicer). All small things which add up in a big way.Metaprogramming. Starting with simple things like
attr_accessor
, then maybe something a bit more advanced if they don't immediately see the benefits. Don't try and compare things to lisp and wax on about programs writing other programs... people will just think you are smoking something. Stay simple and hammer home the point that you don't have to keep writing the same crappy boilerplate code anymoreAs a good "finale", show them some normal NUnit style tests with all the mess of
Assert.NotEqual<string> blah
that they usually have, then say "here's the same code written in ruby" and show them it written using rspec (it will be half the length and 10 times easier to read... if that doesn't sell them, nothing will).
I am approaching it as an opportunity to highlight the benefits of Ruby over C#.
I'm not sure this is the right thing to do. If the tone of your talks is, "Ruby is cool because you can do x in it!" you'll lose your C# audience very quickly. They'll answer, "We can simulate x in C# if we want to, but we don't have much use for x in our designs." or perhaps, "If you think you need to do x then you're doing it wrong!"
They won't understand how Ruby can help them until they understand Ruby. Why not take them through some toy problems and show them how a Ruby programmer would solve them? Teach them the Ruby way. A week later, when they're looking at a problem they're having, one of them will say, "Well gee, I know how to solve this, but if I was using Ruby it would be a whole lot easier...."
In addition to what everyone else have said, Open Classes is an important feature of Ruby that is worth mentioning: (example stolen from Ruby From Other Languages)
class Fixnum
def hours
self * 3600 # number of seconds in an hour
end
alias hour hours
end
# 14 hours from 00:00 January 1st
# (aka when you finally wake up ;)
Time.mktime(2006, 01, 01) + 14.hours # => Sun Jan 01 14:00:00
I know, patching like a monkey should be avoided, but I think that highlighting this feature to newcomers should give them an idea about the philosophy behind Ruby. Just remember to say: "Kids, don't try this at home!"