Response to Paul on Ruby

Ruby seems to be like crack, once you have some you want more, but that doesn’t necessarily mean that it is good for you. Paul Stovell recently posted up an article entitled Ruby for .NET Developers which does a really good job of pointing out some of the key features of developing on the Ruby platform (note that Ruby is a language AND a platform whereas .NET is a platform which has languages likes C#, VB.NET, IronPython and soon, IronRuby).

Paul lists out a few bullet points which highlight some of the syntactic differences, nothing that is really earth breaking but I did find the following things interesting:

  • Ruby strings are not immutable.
  • Ruby does its own scheduling.

I could probably get used to a runtime where strings weren’t immutable again but I don’t know if I really want to. In some instances mutable strings can have performance advantages over immutable strings, but if you aren’t careful you can introduce some really nasty bugs at the same time.

Ruby doing its own scheduling was what I found really alarming and it strikes me that it could be one of its biggest limiting factors. Early versions of the Java runtime used one single thread and quickly found out that they were missing out of the benefits of scheduling being done lower down in the stack. I am sure that Ruby will change this in the future as the amount of time and resources that can be mustered to support writing OS specific threading code increases. Maybe IronRuby might actually help the Ruby community in this respect.

Paul also made a big deal of the block syntax in Ruby and how closures work. In some instances the syntax can be more compact, but the argument that they are significantly better than something like C# anonymous methods is pretty weak, and even weaker once C# 3.5 ships and we get expression syntax. For example:

     customers.ForEach(x => Console.WriteLine(c.Name));

I’ll have to double check on my Orcas machine that I can have an expression that returns a void value, but I suspect that I can. I’m not really suggesting that C# is better than Ruby, but I am suggesting that if you take a big sip of another cup of kool-aid you can often forget what your current language already has in terms of features.

7 thoughts on “Response to Paul on Ruby

  1. Paul Stovell

    >> what your current language already has

    You mean *future* lanuage?🙂

    The string thing worried me too – I think I’d prefer the safety of .NET’s strings to the performance of Rubys.

    Ruby’s threading is interesting because it’s lightweight – with a native thread you’re looking at 1MB overhead for every thread you use up, whereas Ruby threads have a very minimal overhead. Many functional languages are implemented the same way to get the benefits of spinning off many quick little “threads” rather than using 50MB worth of thread overhead. There are certainly some disadvantages but I think there’s a possibility for advantages there too and I’m keen to see what happens in future.

    The biggest thing that worried me was that things like integers, strings and boolean values can be null, since there’s no typing. Since every variable can be null, you can’t really make use of the stack (since null == 0, so you couldn’t tell the difference between 0 and null for an integer). Imagine allocating a boolean value as a local variable – there’s one bit allocated to the heap (to store the value) and another allocated to the stack (to point to the bit on the heap) just so that it can be null. So for most of the basic types, you’re using up twice the memory (for a longer time, since even bool’s have to be garbage collected).

    However the thing that attracts me most about the ruby world isn’t so much the language, but the values of the community. I’ll wait till I’ve spent more time with it before I post on that one.

    Paul

  2. Paul Stovell

    >> The biggest thing that worried me was that things like integers, strings and boolean values can be null

    Obviously strings can already be null and are reference types – that was a mistake.

  3. Kevin Daly

    I’m agnostic on the subject of Ruby per se, but I’ve had it to *here* with the Rails cultists. As soon as people start telling me that something “forces you to do it the right way” I want to tell them to go away and grow up, or possibly learn to actually program.
    And don’t get me started on The Abomination That Is Active Record.

  4. Kevin Daly

    PS. I also believe that .NET development is currently in a very perilous state, because people have moved from adopting useful lessons from, for instance, the Java community and progressed to buying their pathetic framework obsession lock, stock and barrel. I see a lot of Death By Computer Science (with people wasting a lot of time congratulating themselves for ideological correctness based on the complexity they’ve added to their solutions in order to cater for situations that won’t arise, while neglecting the part that actually *does* someting) these days, to the extent that I would like to see YAGNI more forcefully restated as YDFNI (anyone can work out what that means).

  5. Charles Oliver Nutter

    For what it’s worth, JRuby chose not to use green (self-scheduled) threads, deferring to Java’s threads, and it sounds pretty much like Ruby.NET will do the same. You’re right, it does seem to be a limiting factor, but perhaps not in the way you’d expect…it’s more an issue of being able to spin off threads when you want to than having everything parallel all the time. For that, multiple processes do a pretty good job. You just start to see the seams when you actually *want* threads specifically.

  6. Pingback: Windows Forms: A cool use for extension methods and LINQ expressions. « notgartner

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s