Archive for October 2008

With the recent release of Silverlight 2 and the latest version of the Dynamic Languages SDK, now seemed like a good time to write a simple Silverlight application in Ruby. Once you’ve got all the bits downloaded, installed and extracted, find yourself a fresh new folder and open a command prompt. I should note that I put the scripts folder of the Dynamic Languages SDK on my path variable before opening the command prompt. At the prompt type:

sl ruby <application_name>

replacing <application_name> with the name of your application. To see it running type:

server /b

Navigate to index.html and there’s the app running.

Right – time to fiddle. Open the app.xaml file and add a button. Here’s my xaml file:

If you’ve ever wanted to use a dynamic language and target the ASP .NET platform, you’re in luck. First step is to visit this download page and download the samples and documentation – I’m assuming you already have IronPython installed. The documentation contains a walkthrough and some how-tos. There’s also a useful post from Jimmy Schementi here that guides you through an introductory example step by step. I always like samples that run as expected and are simple enough to understand quickly.

PDC is coming up fast. I’m heading out for the conference in a couple of weeks and was just reviewing the sessions I’d like to attend – spoilt for choice. Worth keeping an eye on the blog and the twitter feed for the latest info. Those of you attending will be getting a little something.

It seems impossible to avoid closures when reading about Ruby. What is slightly unclear is what exactly one of these closure things is and what they should be used for. According to Wikipedia, a closure is:

"a function that is evaluated in an environment containing one or more bound variables. When called, the function can access these variables"

"Essentially a closure is a block of code that can be passed as an argument to a function call."

He goes on to explain that a key feature of closures is that:

"they are a block of code plus the bindings to the environment they came from"

Which leads us back to the Wikipedia definition. He also points out that in a language that doesn’t support closures, he misses them. I get the feeling that this is a language construct which is best understood by usage rather than explanation. And there’s some stylistic preferences. Consider this example from a useful primer on closures:

The author describes this code as "beautiful to look at, and with a quick glance, you can tell exactly what it does" – I’m not sure I agree on either point. I’ve seen a fair amount of Ruby that has impressed me with its expressiveness – this excerpt doesn’t make that list. In my search for more insight into closures, I found this is a good starting point – an executable piece of exploration (found via RubyInside.)