.NET

Dynamic Language Plus .NET

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:

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.

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.

Video

This month's Dr. Dobb's Journal

This month,
Dr. Dobb's Journal is devoted to mobile programming. We introduce you to Apple's new Swift programming language, discuss the perils of being the third-most-popular mobile platform, revisit SQLite on Android
, and much more!