Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Apply IronRuby to Get Started Building Next-Generation UIs

IronRuby represents the marriage of the Ruby language to the .NET Common Language Runtime.


advertisement
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).

Ruby 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.

The Language
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.

Building IronRuby
 
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.

Downloading IronRuby
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.

Figure 2 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=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' require 'PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' # 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 DropShadowBitmapEffect = System::Windows::Media::Effects::DropShadowBitmapEffect Vertical = System::Windows::VerticalAlignment



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap