InfoQ

News

IronRuby on Silverlight Demo at RubyConf

Posted by Robert Bazinet on Nov 15, 2007 09:00 AM

Community
.NET,
Ruby
Topics
Dynamic Languages ,
.NET Framework ,
Silverlight
Tags
IronRuby ,
RubyConf ,
DLR

John Lam recently gave the folks at RubyConf a sneak-peak to what is coming from Microsoft's commitment to Ruby running on its Dynamic Language Runtime (DLR) and of course, Silverlight.

The demonstration was different than other Silverlight demonstrations, where  instead of writing XAML markup to have the Silverlight engine render, code was written in Ruby.   Quoting John Lam:

This is one of the first (to my knowledge) examples of a code-first Silverlight 1.1 application. Most Silverlight applications that generate UIs do so by creating a XAML string that they feed to the XAML parser. When you have a language as beautiful as Ruby, it's a shame to be creating trees via strings.

XAML markup looks like this for the demo:

<Storyboard x:Name="Timeline1" TargetName="ScaleTransform1">
  <DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
      Storyboard.TargetProperty="ScaleX">
    <SplineDoubleKeyFrame KeyTime="00:00:00.0" Value="0.200"/>
    <SplineDoubleKeyFrame KeyTime="00:00:00.2" Value="0.935"/>
    <SplineDoubleKeyFrame KeyTime="00:00:00.3" Value="0.852"/>
    <SplineDoubleKeyFrame KeyTime="00:00:00.4" Value="0.935"/>
  </DoubleAnimationUsingKeyFrames>
  <DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
      Storyboard.TargetProperty="ScaleY">
    <SplineDoubleKeyFrame KeyTime="00:00:00.0" Value="0.200"/>
    <SplineDoubleKeyFrame KeyTime="00:00:00.2" Value="0.935"/>
    <SplineDoubleKeyFrame KeyTime="00:00:00.3" Value="0.852"/>
    <SplineDoubleKeyFrame KeyTime="00:00:00.4" Value="0.935"/>
  </DoubleAnimationUsingKeyFrames>
</Storyboard>

Microsoft has committed to running dynamic language on the DLR and with that, they are developing IronRuby on the .NET CLR which is a full implementation of the Ruby programming language.

A goal of writing code for the DLR is to be able to write native code and not have to hand-code XAML.  This would avoid the XAML above and let developers write Ruby like this:

class BounceAnimation < AnimationBase
  def initialize(scale_transform_element)
    @obj = Wpf.build(Storyboard, :name => random_name,
        :target_name => scale_transform_element) {

      add(DoubleAnimationUsingKeyFrames, :begin_time=>'00:00:00',
        :target_property => "ScaleX") {

        add(SplineDoubleKeyFrame, :key_time => '00:00:00.0', :value => 0.200)
        add(SplineDoubleKeyFrame, :key_time => '00:00:00.2', :value => 0.935)
        add(SplineDoubleKeyFrame, :key_time => '00:00:00.3', :value => 0.852)
        add(SplineDoubleKeyFrame, :key_time => '00:00:00.4', :value => 0.935)
      }

      add(DoubleAnimationUsingKeyFrames, :begin_time=>'00:00:00',
        :target_property => "ScaleY") {

        add(SplineDoubleKeyFrame, :key_time => '00:00:00.0', :value => 0.200)
        add(SplineDoubleKeyFrame, :key_time => '00:00:00.2', :value => 0.935)
        add(SplineDoubleKeyFrame, :key_time => '00:00:00.3', :value => 0.852)
        add(SplineDoubleKeyFrame, :key_time => '00:00:00.4', :value => 0.935)
      }
    }
  end
end

The ability to write Ruby is easier and more intuitive than writing XAML and easier to express intent.  Although these features were shown during the demo, the bits will not be available until the next CTP of Silverlight 1.1 where developers will be able to run IronRuby in the browser. 

More information about IronRuby can be found on the IronRuby web site and the source code from the demo is available from John Lam's blog.

 

2 comments

Reply

More like Java code by Zak Mandhro Posted Nov 16, 2007 9:49 AM
Re: More like Java code by Nicholas Cancelliere Posted Nov 20, 2007 11:03 AM
  1. Back to top

    More like Java code

    Nov 16, 2007 9:49 AM by Zak Mandhro

    This looks more like Java code. Perhaps a Ruby abstraction DSL could be implemented to make the code more Ruby-like? For instance:



    class BounceAnimation < AnimationBase
    def initialize(scale_transform_element)
    @storyboard = Storyboard.new "scale_transform" do
    key_frames :for=>:double_animation, :begin=>'0.0', :target=>:scale_x do
    at '0.0', :spline_double=>0.2
    at '0.2', :spline_double=>0.9
    end
    end
    .
    .
    end
    end

  2. Back to top

    Re: More like Java code

    Nov 20, 2007 11:03 AM by Nicholas Cancelliere

    I agree with Zak. One of the things I love about Ruby is how elegant the code is. Verbosity does nothing in my book to win me over, and is primarily why I get turned off by Java.

Exclusive Content

Ruby.rewrite(Ruby)

In this RubyFringe talk, Reginald Braithwaite writes Ruby code to read, write, and rewrite Ruby. Demos include extending Ruby with conditional expressions, call-by-name and more.

Book Except and Interview : Aptana RadRails, An IDE for Rails Development

Aptana RadRails: An IDE for Rails Development by Javier Ramírez discusses the latest Aptana RadRails IDE, a development environment for creating Ruby on Rails applications.

Fast Bytecodes for Funny Languages

Cliff Click discusses how to optimize generated bytecode for running on the JVM. Click analyzes and reports on several JVM languages and shows several places where they could increase performance.

Scott Ambler On Agile’s Present and Future

Scott Ambler, Practice Lead for Agile Development at IBM, speaks on the current status of the Agile community and practices having a look at the perspective of the Agile’s future.

Manager's Introduction to Test-Driven Development

Dave Nicolette and Karl Scotland try to introduce non-technical managers to one of the most popular Agile development techniques: Test-Driven Development (TDD).

Structured Event Streaming with Smooks

Smooks is best known for its transformation capabilities, but in this article Tom Fennelly describes how you can also use it for structured event streaming.

How to Work With Business Leaders to Manage Architectural Change

Successful architectures evolve over time to meet changing business requirements. Luke Hohmann presents how to collaborate with key members of your business to manage architectural changes.

Colors and the UI

In this article, Dr. Tobias Komischke explains how colors used in a GUI can influence our interaction with a computer and offers advice on using the appropriate colors for the interface.