etting popular open source software (OSS) languages running on Microsoft .NET started when Microsoft adapted Python, creating the .NET version called IronPython. The latest OSS project to get the Microsoft treatment is IronRuby
, which is part of a new Microsoft focus on dynamic languages. IronRuby and IronPython are big players in Microsoft's Silverlight project, which is based on the Dynamic Language Runtime (DLR).
is a relatively new language with a large and enthusiastic following in the Web 2.0 world, primarily generated by Ruby on Rails (RoR). Created by David Heinemeier Hansson of 37signals
, Ruby on Rails
is a web framework intended for developing database-driven applications using the Model-View-Controller (MVC) pattern.
Ruby was first released to the general public in 1995. Heavily influenced by Perl and Smalltalk, as a dynamic and heavily object-oriented language, it also shares some similarities to Python. Functionally, the language uses a single pass interpreter, although both the JRuby
and IronRuby implementations make use of a virtual machine approach to improve performance.
However, Ruby has some basic philosophical differences from its progenitor languages. Unlike Python, strings are mutable, meaning they can be changed in place—and you can't copy one by simply making a copy of the reference. Depending on how you implement heavy string manipulation tasks, such mutability could have performance implications. The languages use different object models, and while zealots on both sides will argue the merits of each, it really comes down to personal preference in the end. Programmers tend to stick with languages they're comfortable with, because comfort leads to higher productivity.
IronRuby: The Project
John Lam is the creator and chief enthusiast behind RubyCLR, an early implementation of the Ruby language on top of the .NET framework. The whole idea for RubyCLR came from John's interest in Avalon (now Windows Presentation Foundation), Indigo (now Windows Communication Foundation), and the Ruby language. He used a project for his two-year-old son as the motivation to build the tool that eventually became RubyCLR.
In October of 2006 John Lam announced he was going to work for Microsoft and would continue his efforts there. IronRuby is the result of those efforts. The name pays homage to IronPython and the groundwork laid by Jim Hugunin and others. John Lam's blog
has a number of entries about IronRuby including installation instructions and a link to download the first alpha sources.
|Figure 1. Successful Build: You can see the output that results from building IronRuby targeting the .NET 2.0 framework.|
You can download the IronRuby source
from John Lam's blog and build the Ruby interpreter from scratch. To do that, you'll need to install the Microsoft .NET 2.0 redistributable (or later) before you'll be able to build the code. You need to make only one small change in the build.cmd
file to point at different versions of the .NET framework, which lets you target either the 2.0 or the latest 3.5 framework
release. Figure 1
shows the result of building against the .NET 2.0 framework.
If you're not interested in building IronRuby directly from the source, you can download a utility called DLR Pad
. This tool includes DLL files for both IronPython and IronRuby. DLR Pad was created as a tool to facilitate interactive programming with XAML
and either IronPython or IronRuby. The key to the tool is the use of the DLR.
|Figure 2: XAML Application: Here's DLR Pad loaded with a simple XAML-based UI and some Ruby code.|
The download contains the DLRPad.exe
file along with additional DLL files for IronPython, IronRuby and other supporting libraries. You must have the .NET 3.5 runtime installed for this application to work, but it works on both Windows XP SP2 and Windows Vista.
shows a screen shot of DLR Pad loaded with a simple three-button-pane XAML example.
The code for this application uses a nice feature of Ruby that lets you define constants in a separate file and then "require" that file in the same way you would use include
to include a file in C. In Figure 2
, you can see the require
command in the code, which causes Ruby to include a file named wpf.rb
that defines some shortcuts, as follows:
# Reference the WPF assemblies
require 'PresentationFramework, Version=188.8.131.52,
require 'PresentationCore, Version=184.108.40.206,
# Initialization Constants
Window = System::Windows::Window
Application = System::Windows::Application
Button = System::Windows::Controls::Button
StackPanel = System::Windows::Controls::StackPanel
Label = System::Windows::Controls::Label
Thickness = System::Windows::Thickness
Vertical = System::Windows::VerticalAlignment