Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Open Source

Dynamic Language Plus .NET

Shay Friedman is a Microsoft Visual C# amd IronRuby MVP, and author of IronRuby Unleashed.

IronRuby 1.0, a recently released implementation of Ruby hosted in the .NET Framework and supported by Microsoft, is designed to provide integration between Ruby and .NET code, providing a simpler, less painful way to share code between the two.

Dynamic languages such as Ruby offer something that static languages don't: simplicity. They're designed to get jobs done fast and easy. And since most of the action occurs at runtime, developers can focus on writing better code. Microsoft added support for dynamic languages four years ago in the .NET Framework by implementing the Dynamic Language Runtime (DLR) component on top of the .NET Common Language Runtime, which provides special services for dynamic languages. IronRuby was one of the first languages identified as a candidate for .NET dynamic language support.

With .NET everything is built on top of the CLR, so sharing code among languages is easy. IronRuby 1.0 has been released with full source code under the Microsoft Public License. (Download IronRuby at ironruby.codeplex.com/.) IronRuby's performance is excellent. It's two to four times faster than the main Ruby language implementation, according recent benchmarks, making it a top choice for a Ruby interpreter on Windows.

In one recent project, I needed to detach a folder from Subversion supervision, and my only option was to export the files to a different folder. I had to do this quickly, so I turned to Ruby. While I hadn't intended to use IronRuby, I figured out that Subversion SVN files were read-only, and I needed to pull over all of them using recursion to make them available for deletion. A Web search revealed that Windows Management Instrumentation provided an easy solution: I used IronRuby and .NET's System.Management assembly to execute the WMI commands from my Ruby code. It took me all of 10 minutes to develop the tool.

IronRuby is a bridge between Ruby and .NET, making the entire .NET Framework available to Ruby developers, including frameworks such as WPF, Silverlight, and ASP.NET. For .NET developers, the whole Ruby world is accessible, including Ruby on Rails; testing frameworks such as Cucumber; and Ruby's powerful built-in capabilities.

The DLR makes the task of calling code straightforward, making IronRuby great for adding extensibility features to existing .NET apps. To execute IronRuby code, all you write is:

ScriptEngine engine = IronRuby.Ruby.CreateEngine();
engine.Execute("puts 'Hello from IronRuby'");

You can also set variables to be used within scripts and get return values from executed code. The simplicity of this process will ensure that this kind of extensibility is common in the near future.

Internal Tools And POCs

C# code's execution process is similar to IronRuby's, but it skips the DLR and goes directly through the CLR to get executed on the target machine. This similarity, along with the ability to easily use .NET assemblies in IronRuby code, makes IronRuby ideal for .NET developers to use to write internal tools and proofs-of-concepts; they can use Ruby, but stay within the .NET framework boundaries. The code can be written faster, while letting developers experience another language.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.