I’ve heard about the Ruby programming language off and on for a few years. Recently I happened upon an online tutorial for it. The tutorial runs a Ruby interpreter inside your browser. It takes you through a series of steps to introduce you to the language. It keeps track of what you’re doing so that when you finish a step, it automatically moves on to the next one. Pretty slick.
I gave it a try, and I must say I’m impressed. By the end it had me setting up a rudimentary blog that displayed inside an HTML popup window. It basically took all of 10 lines of code (with some library support)! The language packs power in a simple-to-program structure. I saw quickly that the language was designed to be intuitive. Rather than giving the runtime environment a bunch of types to manipulate, in order to get the result I want I just basically tell it what I want. It can figure out what types things need to be.
I’ve heard some people say that the syntax looks like Scheme. I don’t understand this. As I explain below, the language operates in a way that is Scheme-like, but the syntax looks more like Smalltalk to me.
It contains properties of an imperative, object-oriented language, and of a functional language. By “functional language” I mean a language that operates on the rule that the value of a variable, or input to a function, is always the result returned from a function, though symbols or data elements have their own intrinsic values. There are some built-in functions to get things going.
today – 2.weeks
to get the date from 2 weeks ago. It’s possible to do something almost as simple in C# (from .Net 1.1), but it’s not as concise:
DateTime.Today() – TimeSpan.FromDays(14.0);
You can do things with numeric constants in C# similar to what you can do with them in Ruby, such as “2.toString()”, since “2” resolves to an Int32 type, which has this method. However, there’s nothing like “2.weeks” in C#, converting “2” to a time-span object with a value representing 2 weeks time.
You can also construct your own classes in Ruby.
Every expression or command returns some kind of value automatically. This enables you to string together nested statements where each “feeds” off the other.
There’s been a lot of news in some circles about Ruby on Rails. “Rails” or “RoR,” as it’s called for short, is a web application framework for Ruby. It adds some capabilities to Ruby that make it more of a web application platform that web developers would be familiar with. I’ve heard that the meaty contribution it makes is database connectivity.
I did a little research and found some .Net projects that allow .Net developers to use Ruby.
There’s the Ruby/.Net bridge. This provides an interoperability layer between the .Net runtime and the Ruby runtime. You can program in Ruby, using the Ruby interpreter, and use .Net Framework classes. It says that this works “vice versa” as well, but I don’t see how that’s done, from their documentation.
(Update 9/23/08 – Apparently the Ruby/.Net bridge is gone. Maybe it was mirrored on another site and is still available, but the official site at “SaltyPickle” is gone.)
There’s the open source Ruby.Net compiler from Gardens Point at the Queensland University of Technology in Brisbane Australia. It actually compiles Ruby code into MSIL that’s runnable on the .Net 2.0 runtime. It doesn’t produce optimized code, nor does it guarantee interoperability with other .Net languages, at this point. It was released recently in its first beta.
There’s also RubyCLR, which currently operates similarly to Ruby/.Net bridge.
I haven’t used any of them yet (just found them). From the looks of things, I would consider all of these projects as works in progress. In other words, use at your own risk if you’re planning on using any of them for production software projects. They might be fun to play around with though.
Though there is much excitement in some circles in the software world about Ruby, I did just a quick survey on Dice of Ruby programming jobs nationwide, and the number is paltry. I suspect one reason it hasn’t gotten more popular is due to its unorthodox programming style. Most programmers are used to imperative, Algol-like languages, like C/C++, Java, C#, VB 6, VB.Net, etc. It takes some work to get used to a functional language. In the case of Ruby the effort to understand it might be worth it.