Wow. That was a fun talk that Jim and I did at Mix.
For the Ruby fans in the audience, here was the final version of the application that we wrote:
# This downloads a compiled C# assembly that contains a Button
require 'Silverlight.Samples.Controls,Version=0.0.0.0'
# This imports a JS and a VB module that each contain code that we will use
JS = require '3DText.js'
VB = require 'technorati.vbx'
# We don't have include working yet ...
Controls = Silverlight.Samples.Controls
Document = System.Windows.Browser.HtmlPage.Document
def initialize(sender, args)
# Create an instance of the downloaded C# button
b = Controls.Button.new
b.text = "Click Me"
JS.initialize
# Map Ruby block to .NET event from C#
b.click do |sender, args|
JS.clearList
# This uses a member injector to retrieve a reference to a HTML
# input element from the hosting HTML page
term = Document.searchTerm.value
# This retrieves data from Technorati via Yahoo Pipes serialized
# as JSON data, and then runs a LINQ over Objects query against it
items = VB.GetTitles(term)
# Blocks work, yay!
items.each { |item| JS.initializeName(item) }
# Play that funky designer animation
JS.playAnimation
end
root.Children.Add(b)
end
Keep in mind that the Ruby code here was done in about 4 weeks worth of dev time by our stud developer Tomas Matousek (of Phalanger fame, and my office-mate) with some random input from yours truly.
Great stuff, Can i run that code on Silverlight 1.1 alpha?
Posted by: krishna | May 01, 2007 at 07:28 PM
Hey John
great stuff, really. having a common platform for dynlangs is going to make a whole lot of difference, just like CLI/CLS did for static languages; it's going to finally rid us of text-based interfaces like powershell does compared to bash and its likes. so cool!
now that the curtain has been lifted, can you revisit some of my last questions?
- is it going to be as easy to call into dynlangs from c# as it is the other way round? can I finally implement libraries using dynlangs? interfaces?
- is there any discussion about a groovy-like language for the DLR? what are your thoughts on this? VB is probably not going to please the lambda-the-ultimate-crowd, right? I assume you know the discussion from the java world, so i'll spare you any additional arguments.
- and finally, considering all the great dynlang momentum, are there any plans to get stuff like AOP or metaprogramming into C# or other static CLR languages? given your past, i think you'd know, right?
- jim wrote about a lang.net conference in july. will you be there? would we be able to discuss this stuff there? is this conference by invitation or first come/first serve?
thanks a lot,
stefan
soooo tired of tinkering with dynamic proxies and stuff ;-)
Posted by: Stefan Wenig | May 02, 2007 at 12:09 AM
That code looks very, very familiar. Very RubyCLR like in fact :)
My favorite feature request:
b = Controls.Button.new do
text "Click me"
font "Verdana"
fontSize "12pt"
end
Hopefully the above will be possible just by standard meta programming tricks. THat is, overriding and updating methods on .NET objects from the ruby side.
The above also points toward a very nice XML builder-like interface for constructing your GUI ...
Posted by: Justin | May 02, 2007 at 12:55 PM
Krishna, no you cannot run that code in the current public bits because they lack support for Ruby and VB. Give us some more time and we'll get Ruby and VB bits out to all of you.
Posted by: John Lam | May 02, 2007 at 02:14 PM
Justin - you should be able to just do what you proposed using metaprogramming magic once we get enough features implemented in Ruby.
Posted by: John Lam | May 02, 2007 at 02:57 PM
Stefan,
Send me some mail (jflam) and I'll get you onto the invite list for Lang.Net - we're working on putting it together now.
As for your questions:
- we are massively resource constrained now to deliver two languages (Python/Ruby) in our group, so we don't have any bandwidth for other languages. You're more than welcome to implement groovy on DLR if you want :)
- interfaces are the easiest way to call back into DLR code
- I have no idea about AOP-like plans ... but we can talk about whether that's a good idea at Lang.Net :)
Posted by: John Lam | May 02, 2007 at 09:54 PM
Hi John,
Congrats on getting this far!
I'm a little bit concerned about Ruby compatibility when I see this code sample of yours... It looks, first of all, like your require-string take arbitrary stuff that actually identifies an assembly; how would this work with for example RubyGems? Assembly definitions wouldn't even be valid file paths in many cases...
And the second point is also about require: from the example, it looks like it returns a module/class? If that's the case, once again, how will the applications that depend on the boolean result from require work?
It looks like you have choosen to retain the exactly same assembly/class names as .NET uses in all. How have you implemented this? With method calls? Do you have problems with overlap between these method calls and regular constants? (I bet you will get those problems later, otherwise...)
In what kind of context does this run, btw? It looks like the initialize method actually gets defined one the singleton class of toplevel. In that case I take it that this initialize have _nothing_ to do with regular Ruby allocations schemes, with the allocate and new methods.
I like what you have done with the event handlers. Do I read it correctly that methods/delegates like onClick gets turned into a click-method that takes a block? That's very neat, if that's the case.
Anyway, not to nitpick; I'm just very interested in how you plan to solve these problems, or if IronRuby will have the same problems with incompatibilities that other languages implemented by MS have been known to suffer from.
Posted by: Ola Bini | May 05, 2007 at 08:45 AM
Ola, thanks for sending in this detailed set of comments!
We thought about every single issue that you brought up here and debated them at length. I kind of didn't want to call them out in the comments to see what folks thought without our bias.
I'm on vacation right now (sneaking in a blog comment or email in here or there), but I'll answer each and every one of your concerns in a separate post. Your point about context is extremely important and probably the one that we need the most feedback on.
About event handlers - exactly what you described.
More later ...
Posted by: John Lam | May 05, 2007 at 01:11 PM
Thanks John,
I'm looking forward to that post. I'm sure you have rationalizations, and it will be very interesting to read them.
Posted by: Ola Bini | May 05, 2007 at 01:23 PM