First Look at IronRuby

Over the last few years we've been working to make .NET and the CLR a great environment for dynamic languages.  About 14 months ago we formed a dedicated group within my team that has been focused on adding richer CLR runtime support for dynamic languages, as well as delivering first class .NET implementations of popular dynamic languages.

DLR Background

This spring we shipped the first preview release of a new .NET library that we call the "Dynamic Language Runtime" (or DLR for short).  It provides a set of features on top of the CLR designed explicitly for dynamic language scenarios.  These include a shared dynamic type system, language hosting model, and support to make it possible to generate fast dynamic code.  These features make it much easier to build high-quality dynamic language implementations on .NET.  These implementations can access and use any of the APIs in the .NET Framework, as well as easily interoperate with code written in any other .NET language (for example: you could write a Ruby class that invokes and uses a C# class, which in turn invokes a Python class).

This spring at the MIX 07 conference we announced that Microsoft will be shipping 4 dynamic language implementations of our own for .NET:

  • IronPython
  • IronRuby (new)
  • Javascript
  • Dynamic VB (new)

The source code of our IronPython implementation, as well as the source code for the underlying DLR library, was published on CodePlex in April.  You can download both of them today from the IronPython codeplex site.  All of the source is made available under the MSPL permissive license - which provides full commercial and non-commercial modification rights.

IronRuby Pre-Alpha Release

Today we are making available the first public drop of our IronRuby implementation.  You can learn more about how to download the source, build it, and try it out from John Lam's blog post here.

Today's IronRuby drop is still a very early version, and several language features and most libraries aren't implemented yet (that is why we are calling it a "pre-alpha" release).  It does, though, have much of the core language support implemented, and can also now use standard .NET types and APIs.

IronRuby has been architected to take advantage of a new DLR feature we call "Dynamic Sites" - which delivers a fast adaptive call-site method caching implementation.  It also uses the lightweight-code generation features of the CLR.  Lightweight code generation enables dynamic language implementations to create in-memory IL that is then JIT'd into native code at runtime (without ever having to save anything to disk).  This can yield much better runtime performance than interpreted code, and the lightweight codegen feature ensures that once we are finished with the JIT'd code we can optionally garbage collect it to avoid leaking. 

We are releasing today's drop mainly for developers interested in language implementations to start looking at the IronRuby source code, and learn how it was implemented.  Developers interested in playing with an early version of Ruby for .NET can also download it and give it a spin.

IronRuby Project Plans

Next month we will be moving the IronRuby source code repository to be hosted on RubyForge.  As part of this move we are also opening up the project to enable non-Microsoft developers to enlist in the project and contribute source code. We'll then work to implement the remaining features and fix compatibility issues found as more libraries and source are ported to run on top of it. 

The end result will be a compatible, fast, and flexible Ruby implementation on top of .NET that anyone can use for free.

IronRuby "Hello World" Console Sample

If you download and build the IronRuby source code, you are probably wondering "how do I start using it?" 

The easiest way to get started is to run the "rbx.exe" interactive console application that by default is built under the \bin\release directory:

This console shell provides you with the ability to write Ruby code interactively.  After each line, the shell will interactively execute it. 

For example, we could output hello world by typing puts "Hello World":

To output this 10 times in a row, we could type the following:

To use Windows Forms functionality in IronRuby, we could type a require statement that references the System.Windows.Forms assembly, and then use the MessageBox.Show method to display a message in a modal dialog:

IronRuby "Hello World" WPF Sample

One of the benefits of implementing a language on top of .NET is that it enables developers using that language to get full access to the rich framework libraries provided with the .NET Framework.  

For a simple example of this in action, I could create a "HelloWPF.rb" text file and type in the following Ruby code below:

The above code uses the WPF UI framework to create a Window that hosts a StackPanel layout manager that initially contains just a button.  When the button is pressed, a new label control is created and added into the StackPanel (causing it to automatically be flowed in the Window). 

I can then run the above application using IronRuby by passing the "HelloWPF.rb" text file as an argument to rbx.exe:

When I run it I'll get a window with a WPF button (note above I added a nice DropShadowBitmapEffect to it in the code above):

And each time I press the button a new label will be added to the Window:

Not only does having the ability to use all of the .NET APIs provide a lot of power, but you'll notice in the code we wrote how it is possible to naturally integrate .NET APIs into other language syntaxes:

In the code snippet above I'm using the Ruby block language feature (similar to a Lambda expression with C# 3.0 and VB9) to implement a "Click" event handler on the WPF button.  Notice how within the block the standard Ruby naming patterns can be used when accessing any .NET API.  For example, instead of using the "FontSize" property on the WPF Label we are accessing it using "font_size" as the property accessor name. IronRuby automatically handles the naming conversion - enabling developers to program with a consistent naming pattern regardless of their language of choice.

Summary

If you are interested in trying out this first early drop of IronRuby, you can download the source and build it here.

You can then download my WPF sample above and run it yourself here (note: you must have .NET 3.0 or 3.5 installed - since those deliver the WPF APIs).  To learn more about WPF, I also highly recommend Adam Nathan's excellent WPF Unleashed book (read the review comments on Amazon to see why).

Hope this helps,

Scott

60 Comments

  • Once again, it seems, the Developer Division is one of the best organizations within Microsoft. You all are always cranking out impressive stuff. Excellent work Scott! Oh, and I'm desperately waiting for the VS2K8 Beta 2 - will it be dropped soon?

  • Hi Dan,

    Glad you like it! :-)

    >>>>>>> Oh, and I'm desperately waiting for the VS2K8 Beta 2 - will it be dropped soon?

    You'll see Beta2 ship later this week - so only a few more days now.

    Thanks,

    Scott

  • Isn't there a Ruby.NET already? Is IronRuby a name change to Ruby.NET or, are these 2 different products? If these are different, then, pl. explain the differences between Ruby.NET and IronRuby. Thx.

  • Awesome! How did you get permission to use Rubyforge? Are all the lawyers away in Aruba for a junket?

  • Hi Kal,

    >>>>>> Isn't there a Ruby.NET already? Is IronRuby a name change to Ruby.NET or, are these 2 different products? If these are different, then, pl. explain the differences between Ruby.NET and IronRuby. Thx.

    Ruby.NET and IronRuby are separate Ruby implementations for .NET. Ruby.NET was started at Queensland University in Australia. You can find more details about it here: http://www.plas.fit.qut.edu.au/rubynet/

    IronRuby uses some of the Ruby.NET code (Microsoft licensed it), but uses the DLR library for implementing the dispatching and code compilation.

    Hope this helps,

    Scott

  • Hi Scott,

    >>>>> Awesome! How did you get permission to use Rubyforge? Are all the lawyers away in Aruba for a junket?

    All we needed to-do was ask. Chad Fowler and Rich Kilmer (two of the core guys who run RubyForge) are great guys and were very helpful with this.

    Thanks,

    Scott

  • Is beta 2 feature complete?

  • Hi Matt,

    >>>>>> Is Beta2 feature complete?

    VS 2008 and .NET 3.5 Beta2 (which will be out later this week) are pretty much feature complete. We'll do some small features additions/chanegs based on new feedback on Beta2, but 99% of the features are all there.

    Hope this helps,

    Scott

  • I'm curious what little 'twist' is MS going to add to the Ruby language to make it their own.

  • Hi Greg,

    >>>>> I'm curious what little 'twist' is MS going to add to the Ruby language to make it their own.

    The IronRuby project will be hosted on RubyForge and have both non-Microsoft and Microsoft developers working on it. The license also fully allows another group of developers to fork the code and maintain it themselves if they don't think they are doing a good job of it.

    We are definitely committed to making sure IronRuby is a first class Ruby implementation.

    Thanks,

    Scott

  • From what I have seen, Ruby is a great language but among the slowest (2-3x slower than PHP, from what benchmarks I have read). How will IronRuby stack up compared to Ruby in terms of speed?

  • what about a sample of runniny ironruby with asp.net?

  • Hi Justin,

    >>>> From what I have seen, Ruby is a great language but among the slowest (2-3x slower than PHP, from what benchmarks I have read). How will IronRuby stack up compared to Ruby in terms of speed?

    IronRuby is still a pretty young project, and we haven't done performance tuning yet on it. But our initial run of the standard Ruby YARV benchmarks on today's drop look positive (3-6x performance wins in many cases for standard benchmarks). We'll obviously need to make more progress before knowing where things will ultimately end up - but our DLR infrastructure enables languages to run really fast on .NET.

    Hope this helps,

    Scott

  • Thanks Scott,

    speed has been one of my concerns with getting into Ruby and part of what I love so much about .Net.

    I'll take a look at this. Great stuff!

  • Hi .netter,

    >>>>>> what about a sample of runniny ironruby with asp.net?

    IronRuby is still pretty early, and doesn't have enough feature support for this just yet. But I'll post in the future once there is enough to enable this.

    Hope this helps,

    Scott

  • This might seem counter to the idea of dynamic languages, but I was wondering (not having checked out the code myself) if features from the DLR, other additions like what you mention "Dynamic Sites", and lightweight-code generation functionality could be used in non-dynamic languages like C# or VB.NET?? Is the direction of usage one-way here, or duplex? And, if this is possible, what kind of usage scenarios can be envision?

    Cheers.
    Rishi

  • Does anyone else no like the ruby syntax or am I just getting old? Shame there's no dynamic c# on the list...

  • Scott,

    I tried the WPF sample you posted and for some reason it doesn't run. When you have the require 'WPF', shouldn't it be require 'PresentationFramework' (since that's the name of the assembly)?

  • Any Rails like functionality support in the IDE to follow up after the initial release of IronRuby, or is that going to be left up to ISV's?

  • Hi Scott,

    Just wondering, what is your target audience for the DRL? From what I can gather, it's for people already working with Ruby or python that want to leverage the .net framework?

    If so, are there any or many reasons for people who are developing in a completely asp.net or VB.net winforms environment to start using the DLR technologies?

    Regards
    Lomaxx

  • I have VS 2008 Beta 2, and when i attempt to compile this, i get this error,
    Warning as Error: Invalid search path 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib' specified in 'LIB environment variable' -- 'The system cannot find the path specified. ' Microsoft.Scripting
    Just curious how you get it built, since i see your running under 2008 beta2.

    Thanks!


  • Hi Scott,

    Is it possible to write a ruby class that's used by c#? or it works c# object to IronRuby only?

  • You'll see Beta2 ship later this week - so only a few more days now.
    --> Wow. Since it is gonna be feature complete, it will be suitable to start building off something already :) Can't wait though for its release.

  • Hi Rishi,

    >>>>> This might seem counter to the idea of dynamic languages, but I was wondering (not having checked out the code myself) if features from the DLR, other additions like what you mention "Dynamic Sites", and lightweight-code generation functionality could be used in non-dynamic languages like C# or VB.NET?? Is the direction of usage one-way here, or duplex? And, if this is possible, what kind of usage scenarios can be envision?

    The DLR infrastructure can actually be used with any language on .NET - so it is not restricted to only be ing used by traditional scripting languages.

    Having said that, some of the features like "dynamic sites" are designed for languages that don't generate strongly-typed method invocations that resolve down to vtable calls at runtime. Because C# and VB (when in option strict mode) always do this, features like "dynamic sites" don't end up being necessary.

    Hope this helps,

    Scott

  • Hi Javier,

    >>>>> I tried the WPF sample you posted and for some reason it doesn't run. When you have the require 'WPF', shouldn't it be require 'PresentationFramework' (since that's the name of the assembly)?

    Have you downloaded my .zip file above? It contains both a HelloWorldWPF.rb file as well as a WPF.rb file. The WPF.eb file contains the require declaration for both PresentationFramework and PresentationCore - which are the two WPF assembleis you need.

    Hope this helps,

    Scott

  • Hi Lomaxx,

    >>>>>>> Just wondering, what is your target audience for the DRL? From what I can gather, it's for people already working with Ruby or python that want to leverage the .net framework? If so, are there any or many reasons for people who are developing in a completely asp.net or VB.net winforms environment to start using the DLR technologies?

    The DLR enables you to use .NET (including ASP.NET) from other languages besides the core VB and C# languages that most .NET developers use. If you like VB and C#, then it probably doesn't make sense to consider any changes. I enjoyed dabbling with Ruby last night when writing this blog post, but I personally love the new C# release in VS 2008 and am very happy with it.

    Hope this helps,

    Scott

  • Hi Lucas,

    >>>>>> I have VS 2008 Beta 2, and when i attempt to compile this, i get this error: Warning as Error: Invalid search path 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib' specified in 'LIB environment variable' -- 'The system cannot find the path specified. ' Microsoft.Scripting

    >>>>>>> Just curious how you get it built, since i see your running under 2008 beta2.

    Sorry for the confusion - I think the project file might not support building it. You should instead use the "build.cmd" batch file in the root of the IronPython directory to build it.

    Hope this helps,

    Scott

  • Hi Jeremiah,

    >>>>>> Are there any new WPF additions with .NET 3.5 Beta 2? I've seen very little information on it other than FireFox XBAP support.

    There are actually a number of small improvements to WPF in .NET 3.5. Many of these are performance improvements for core scenarios. In addition to FireFox XBAP support, there is also new support for LINQ databinding with WPF. I'm hoping to have the time to blog about the LINQ databinding feature in the future.

    Hope this helps,

    Scott

  • Hi Jason,

    >>>>>> Is it possible to write a ruby class that's used by c#? or it works c# object to IronRuby only?

    I believe this is possible - although I haven't done this myself. If you implement an interface or derive from a base class using Ruby, then you should be able to cast the object to the contract using C# and call it via early binding. You could also probably use reflection if you wanted to invoke it via late-binding using C#.

    Hope this helps,

    Scott

  • Dear Mr. Scott,

    I am at confused/disappoint stage today. You have not made it clear that will Asp.Net support IronRuby in future or not.

    I love asp.net and i wish i could use the ruby language just like C# to create Asp.Net projects.

    IronRuby without Asp.Net support will remain like an Orphan child for ever.

    Your team should make Ruby as a part of language options in VWD like (1) C# (2)VB (3) Ruby.

    I was very disappointed to learn that Asp.Net team is not considering anything about this at this stage.

    I was expecting few examples in IronRuby like IronPython in asp.net futures, since ruby is more popular than python.

    Please clarify and boost my moral.

  • Hi Softmind,

    >>>>>> I am at confused/disappoint stage today. You have not made it clear that will Asp.Net support IronRuby in future or not.

    You will be able to use both IronPython and IronRuby to build ASP.NET applications. IronPython works today (see this old blog post of mine for details: http://weblogs.asp.net/scottgu/archive/2006/11/16/ironpython-for-asp-net-ctp.aspx). IronRuby will work in the future once the IronRuby project is a little further along in their implementation of the language.

    Hope this helps,

    Scott

  • good to hear support for new langauge in the frame work. Do you have any list of the number and name of langauge that can run on the dot net frame work(very curious to know). Good post but dyi ng to see the orcas beta 2. My download manage is just waiting for it. I hope this will surly support vista?(I could not run orcas beta 1 in vista!)

  • Something totally different. I realized that each of your code snapshots (all others are fine) have a kind of blur / wash effect. Why is that?

  • Perhaps I am quite stupid, but I can not see the advantages, and it is quite ugly.

  • A question that is possibly related to this: how is the project for an MVC framework for ASP.NET going? Is it related to IronRuby, because Ruby is so populair in combination with Ruby on Rails? Looking at the long term plans, is IronRuby support and the ASP.NET MVC project something we can see in VS2008 (maybe a service pack) or rather in the version thereafter? I really want this and am already working with Ruby on Rails (I might switch if LINQ didn't look so good).

  • Why rbx instead of irb like current ruby distributions? Seems like equivalent functionality but different names will just become a source of annoyance for any developer who has to move between different Ruby distributions. Or will rbx be different than irb?

  • Hi Dariusz,

    >>>>>> Something totally different. I realized that each of your code snapshots (all others are fine) have a kind of blur / wash effect. Why is that?

    I touched up the code-snippets in MSPaint, and it sometimes does a weird dithering thing on JPG images when it saves them. Sorry about that!

    Scott

  • Hi Mike,

    >>>>>> A question that is possibly related to this: how is the project for an MVC framework for ASP.NET going?

    We have a MVC framework for ASP.NET that we are working on and will talk about more in the future. This is not tied to any specific language - so you'll be able to use it with any .NET language (including VB, C#, IronPython, IronRuby, etc).

    Hope this helps,

    Scott

  • Hi Mark,

    >>>>>> Why rbx instead of irb like current ruby distributions? Seems like equivalent functionality but different names will just become a source of annoyance for any developer who has to move between different Ruby distributions. Or will rbx be different than irb?

    We haven't closed on the final name of the interpreter. If we used "irb" as the name, though, we would conflict if you had both installed on the same system. You can, though, easily map irb to rbx (or whatever the final name is) if you want to avoid switching interpretter names.

    Hope this helps,

    Scott

  • Your team is saving Microsoft. I wonder what that feels like.

  • I'm very interested in using Ruby on a product I'm developing for my company. If I used Ruby.NET for the time being, would I be able to bring that work into IronRuby when it RTMs? Along those lines, will we be able to take code written in pure Ruby and use it directly in IronRuby?

  • "Orcas Beta 2 due this week?"

    Yes. OK I am ready...Where is the link? I must use right now :-)

  • Hello Scott,

    I have heard nothing about Dynamic VB since long. What i have heard is... "its one of the 4languages for DLR "

    VB is Microsoft baby, and Dynamic VB should be another one. It would be great if you can point out few things about Dynamic VB as well, since developers, students, new commers can decide which way to go deciding any one from 6 languages.

  • >>>We have a MVC framework for ASP.NET that we are working on and will talk about more in the future.

    Care to elaborate on this a little bit? =)

  • Are there features of the DLR that you think would apply to Domain Specific Language scenarios?

  • Can the public contribute to the development of Ironpython like it will be able to do to Ironruby shortly? Or is Ironpython only provided in its object and source form for someone to build bt you do not accept community contributions for it.

  • I downloaded Ironruby Pre_Alpha1 Release and started playing with it. It's just great. When I first came to know about Ruby I just not got enough time to play with as I work mainly in .NET. But I like rubly language syntax and power.

    Now I got a chance to learn and play with it as it is in .NET.

    Thanks

  • Really Interesting stuff. We have been waiting for VS (Orcas) for a long time.

    How about Ruby On Rails Support ? - This is the killer Web Framework. Currently we are using the Saphire Steel Visual Studio RonR Development environment.

  • It really rocks on this one. Thanks for Scott bring it out and the team behind this awesome work. Work together with rubyforge is even more worth the praise.

  • Hi Scott - This is really cool stuff - Congrats to the team on all their hard work :-)

    Hey I spotted the DLR Console sample video which had IronRuby enabled in it - but alas the version I downloaded only supported Python and JavaScript. I have Silverlight 1.1 Alpha etc installed and really want to start having a play. Is there a way to mod some of the files on my machine/in IIS so I can get the IronRuby bits in there... (I understand that this will only work for my machine - I just want to start mucking around with it a bit :-) ) Currently I just get an exception when I set the xaml code behind type to text/ruby

    Thanks,

    James

  • Hi James,

    >>>>>> Hey I spotted the DLR Console sample video which had IronRuby enabled in it - but alas the version I downloaded only supported Python and JavaScript. I have Silverlight 1.1 Alpha etc installed and really want to start having a play. Is there a way to mod some of the files on my machine/in IIS so I can get the IronRuby bits in there... (I understand that this will only work for my machine - I just want to start mucking around with it a bit :-) ) Currently I just get an exception when I set the xaml code behind type to text/ruby

    Unfortunately right now we don't have a build of Silverlight that works with IronRuby that is public just yet. I'll ping John from the DLR team to see what the ETA on enabling this is.

    Thanks,

    Scott

  • Hello Scott :-)
    How about writing a ruby class that can be used by c#?

  • Can I do any of this with Visual Studio .NET 2005? Or do I require the beta of Orcas? Thank you.

  • Hi Johnny,

    >>>>>>> Can I do any of this with Visual Studio .NET 2005? Or do I require the beta of Orcas? Thank you.

    All of the above code works with both VS 2005 and VS 2008.

    Hope this helps,

    Scott

  • Hi Scott,

    This is super cool! Can we use IronRuby to create web applications? Kinda like Ruby on Rails framework.

  • Definitely +1 on IronRuby in the DLRConsole app!



  • Is there any chance of phalanger (php-compiler.net) getting adopted by MS. They have a full working version of php compiler and dotnet support. PHP on dotnet would be a really cool idea. You can get a hundred thousand people already skilled in it.

    Thanks.


  • I have VS 2008 and Ruby Alpha, when I tried your wpf example it threw, could not find wpf assemply. I saw in earlier posting that your example is included in the alpha, but I didn't find it. Could you please point me to correct source code link? I used John Lam link and it didn't have wpf.

  • Thank you so much for the the good starter examples. I have question on the WPF button. When I have 2 buttons, only the first button click method gets the control and the second button click method doesn't get the control. Is there something I am doing wrong?
    Thanks again for the excellent example.

  • I am just learning August Blend and some c# and wondered if I can use IronRuby with it and how I might go about trying.

Comments have been disabled for this content.