Nick Sieger: RubyConf: Your Ruby in My CLR tag:blog.nicksieger.com,2005:Typo Typo 2010-11-23T15:02:38+00:00 John Lam urn:uuid:49720d5b-de22-4314-a616-4df6e4141813 2006-10-25T02:33:23+00:00 2010-11-23T15:02:38+00:00 Comment on RubyConf: Your Ruby in My CLR by John Lam <p>Wow&#46; Thanks for the great summary of my talk, Nick! </p> <p>I&#8217;m wary about over&#45;committing to RubyCLR with my other duties at MSFT&#46; So hopefully someone will step up to take my place as the maintainer of RubyCLR so that it can continue moving forward&#46;</p> <p>The good news is that the code is in pretty good shape&#46; The docs, on the other hand, could use some &#46;&#46;&#46; um &#46;&#46;&#46; writing :)</p> Nick urn:uuid:02920ebb-ee7c-4d81-83ab-ab1b94d1f341 2006-10-24T14:41:04+00:00 2010-11-23T15:02:40+00:00 Comment on RubyConf: Your Ruby in My CLR by Nick <p>I updated that paragraph so that it&#8217;s not misconstrued as fact&#46; But I did chat with John over the course of the weekend and that was the impression I got based on those conversations and after listening to his talk&#46; I think MS would rather see Ruby as a full platform language ala IronPython, which is why they&#8217;re financially backing the <a href='http://www.plas.fit.qut.edu.au/rubynet/' rel="nofollow">Ruby&#46;NET</a> project&#46;</p> Dr Nic urn:uuid:39ded271-5b82-420e-bb55-8e6da72d7c5b 2006-10-23T19:15:52+00:00 2010-11-23T15:02:40+00:00 Comment on RubyConf: Your Ruby in My CLR by Dr Nic <p>I think John got a job @ Microsoft so he can continue it&#46; </p> <p><a href='http://www' rel="nofollow">http://www</a>&#46;iunknown&#46;com/articles/2006/10/20/dynamic&#45;languages&#45;microsoft&#45;and&#45;me</p> Nick Sieger urn:uuid:b565842e-e6dc-4ddf-bc06-69de35a90870 2006-10-23T14:16:00+00:00 2010-11-22T18:11:21+00:00 RubyConf: Your Ruby in My CLR <p><strong>John Lam</strong> wanted to build a photo&#45;flash&#45;card application using Avalon and Indigo and Flickr, but also using Ruby as the implementation language&#46; So along the way he decided to build an interop layer (a bridge) between Ruby and the CLR to do it&#46;</p> <p>Now that John has <a href="http://www.iunknown.com/articles/2006/10/20/dynamic-languages-microsoft-and-me">joined Microsoft</a>, his new mission (bigger picture) is to further dynamic language implementations on the CLR&#46;</p> <h2>Bridging type systems</h2> <ul> <li><p>Dynamic methods in the CLR allow you to do better than simply invoking the reflection API&#46;</p> <pre><code>Ruby | C | CLR ============================================ shadow class | dynamic method | instance </code></pre></li> <li><p>Polymorphic inline caching &#45;&#45; caching method dispatches on different call sites based on the assumption that types don&#8217;t change that often</p></li> <li>Generate shadow classes and method stubs using <code>const_missing</code> and <code>method_missing</code></li> <li>Overload resolution happens in the method shims (a one time cost) to choose, e&#46;g&#46;, which constructor to use for <code>System::Collections::ArrayList.new</code></li> <li>Integration is done to make the CLR feel more Rubyish</li> </ul> <h2>Implementation</h2> <ul> <li><p>This changes identity (proxied object):</p> <pre><code>ArrayList.new.as(IEnumerable) </code></pre></li> <li><p>This is less Rubyish, but identity is preserved:</p> <pre><code>IEnumerable.get_enumerator(ArrayList.new) </code></pre></li> </ul> <p>There are trade&#45;offs and warts to a bridge approach to Ruby integration on top of a platform such as the CLR: there is a need to inject artificial type information occasionally to be able to construct CLR objects (e&#46;g&#46;, arrays &#45;&#45; <code>Array.of(Int32).new(3)</code>)&#46; Generics are evil! Simple stuff doesn&#8217;t seem so bad: <code>List.of(Int32).new</code>, but there&#8217;s more pain to be had (see John for details)&#46; John also built a RubyInline&#45;like implementation for the CLR languages too, to allow for getting things done (even if it&#8217;s dirty)&#46; Finally, method overloading is a problem, especially when there is no equivalent Ruby type &#45;&#45; this gave way to <code>instance_shim</code> which is a sort of aliasing method that mixes in type metadata for use by the interop layer&#46;</p> <p>On the other hand, there are many places where Ruby (even in bridged mode) can make the experience of developing on the CLR better&#46; Implementing CLR interfaces is a feature that allows Ruby objects to cross to the CLR side, (e&#46;g&#46;, adding IEnumerable to Ruby Array)&#46; Performance across the CLR boundary (marshalling data) is ~100 times slower than C#, but still fast (3 million calls/second)&#46; Huge benefits are gained from using DSLs in Ruby to help with the implementation of the interop layer&#46; Also, RubyCLR allows mixing in methods into CLR types, so we can re&#45;skin APIs that feel clunky in Ruby&#46; This is really leveraging the power of Ruby in the best possible way&#46;</p> <p>My take is that it looks like the RubyCLR project will probably not be seeing much further development, unless John finds a willing maintainer &#45;&#45; but this is speculation, I haven&#8217;t confirmed with John&#46; Yet, the problem of impedance matching between type systems is a recurring theme in the dynamic language arena, and so John&#8217;s work is valuable in helping us to understand this issue&#46;</p> <h2>More Info</h2> <ul> <li><a href="http://www.rubyclr.com/">http://www&#46;rubyclr&#46;com/</a></li> <li><a href="http://www.iunknown.com/">http://www&#46;iunknown&#46;com/</a></li> </ul>