What features of the Ruby language would you highlight in comparison with C #?

I am talking about a series of conversations with the .NET development team (C #) in Ruby and the environment. I approach it as an opportunity to highlight the benefits of Ruby over C #. First I want to focus on the language itself before moving on to the environment (RoR vs ASP MVC, etc.). What features of the Ruby language would you touch upon?

+7
c # ruby programming-languages
source share
5 answers

I recently spoke with a .NET user group about IronRuby and ran into similar issues. I focused on the fact that:

  • Duck seal. There is nothing silly than List<string> stringList = new List<string>() ;

  • Expressive and concise syntax. Simple things like discarding parentheses, arrays and hash literals, etc. (In combination with duck typing, you get string_list = [] , which is clearly better). All the little things that add up to a large extent.

  • Metaprogramming

    . Starting with simple things like attr_accessor , maybe something is a bit more advanced if they don't immediately see the benefits. Do not try to compare things with lisp and wax about programs that other programs write ... people will just think that you are smoking something. Stay simple and ground so you don't have to write the same crappy boilerplate code anymore.

  • Like a good “finale,” show them some of the usual NUnit style tests with all the Assert.NotEqual<string> blah mess they usually have, then say “here is the same ruby ​​code” and show them that it is written using rspec (it will be half the length and 10 times easier to read ... if this does not sell them, nothing will happen).

+11
source share

Duck seal! This would be less of a problem in C # 4.0, but there were times when I had to duplicate entire blocks of code because two related classes with identical APIs (for my purposes) did not use the base class.

In addition, blocks. C # has lambdas, but the Ruby syntax is prettier, and they are used everywhere in all standard libraries. They are much more part of idiomatic Ruby than idiomatic C #, and this is something important.

Edit
Hash literals are worth mentioning. In general, I would like to emphasize how concise you can be in Ruby, and how it allows you to better express your intention and spend less time trying to make the compiler happy.

+5
source share

I approach it as an opportunity to emphasize the benefits of Ruby over C #.

I am not sure if this is correct. If the tone of your conversation reads: “Ruby is cool because you can make x in it!” you will lose your C # audience very quickly. They will answer: "We can simulate x in C # if we want, but we have little use for x in our projects." or perhaps, "If you think you need to do x, then you are doing it wrong!"

They will not understand how Ruby can help them until they understand Ruby. Why not take them through some problems with toys and show them how the Ruby programmer will solve them? Teach them the ruby ​​way. A week later, when they look at the problem that they have, one of them will say: "Well, yes, I know how to solve it, but if I used Ruby, it would be much easier ...."

+5
source share

Mixing and multiple inheritance.

It is dangerous in the wrong hands, but very useful for the proper encapsulation of things, and not in order to inherit many things that you do not need.

+1
source share

In addition to what everyone else has said, Open Classes is an important Ruby feature worth mentioning: (e.g. 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 that fixes like monkeys should be avoided , but I think that highlighting this function to beginners should give them an idea of ​​the philosophy behind Ruby. Just remember to say, "Kids, don't try this at home!"

+1
source share

All Articles