BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

IronRuby on Silverlight Demo at RubyConf

| by Robert Bazinet on Nov 15, 2007. Estimated reading time: 2 minutes |

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.

 

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

More like Java code 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

Re: More like Java code 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.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

2 Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and dont miss out on content that matters to you

BT