<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Segment7: Static Typing for Ruby</title>
    <link>http://blog.segment7.net/articles/2008/04/16/static-typing-for-ruby</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>The Blog</description>
    <item>
      <title>Static Typing for Ruby</title>
      <description>&lt;p&gt;Last week I went to a presentation by Jeff Foster about &lt;a href="http://www.cs.umd.edu/~jfoster/ruby.pdf"&gt;Diamondback Ruby&lt;/a&gt; (DRuby), a static type inferencer for Ruby.  DRuby's goals are to be simple to use, be flexible enough to handle common ruby idioms, be reasonably useful, and to revert to run-time type checking as needed.

&lt;p&gt;DRuby features its own GLR parser for Ruby grammar with extensions for type annotations and is written in OCaml.  Internally it uses a normalized and simplified ruby subset to perform the type analysis in order to remove ambiguities and simplify flow analysis.

&lt;p&gt;Type inference is fed a prebuilt set of type annotations derived from the core library that look very similar to rdoc.  The annotation system can handle variable arguments to methods, type intersections and type unions.  Basically, this means it's expressive enough to handle String#slice which can be called six different ways.

&lt;p&gt;For details on the type inferencing itself, you should read &lt;a href="http://www.cs.umd.edu/~jfoster/ruby.pdf"&gt;the paper&lt;/a&gt;.  There are currently some limitations in DRuby, among them are unsuitability for large applications due to time constraints and too many false positives, it flattens namespaces such that A::C and B::C are considered the same, and it doesn't handle #eval.

&lt;p&gt;On a set of eight benchmark applications, five required some minor modifications for DRuby to operate (described in the paper), and three of the eight had false positives.  I found two of the false positives interesting, as I think the code highlighted by DRuby is questionably written.

&lt;p&gt;The false positive in sudokosolver is from a method that returns an Array or false then performs a run-time type check to do the appropriate thing with the results.  The false positive in ObjectGraph involves a String that is duck-typed into a StringIO if StringIO wasn't required through a singleton class.

&lt;p&gt;Compared to other static typing add-ons for Ruby, this is the most promising one I've seen.  There's no type annotations required to muck up my existing applications (they would be provided with DRuby), no penalties for checking at run-time, and it's smart about functions as convoluted as String#slice.

&lt;p&gt;Unfortunately, since it hasn't been released into the wild yet (the target date we were given was sometime this summer) it's hard to say if it how useful it would be.  Judging from the two false positives given, it may have some utility as an equivalent to a flog, though.
</description>
      <pubDate>Wed, 16 Apr 2008 16:36:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:d433a445-3300-480c-87a7-415a9ff680b2</guid>
      <author>drbrain@segment7.net (Eric Hodel)</author>
      <link>http://blog.segment7.net/articles/2008/04/16/static-typing-for-ruby</link>
      <category>Ruby</category>
    </item>
    <item>
      <title>"Static Typing for Ruby" by Eric Hodel</title>
      <description>&lt;p&gt;I was considering the add-ons that allow you to add type declarations to your methods that typically do run-time static type checks.  I hadn&amp;#8217;t heard of Duby.&lt;/p&gt;</description>
      <pubDate>Thu, 17 Apr 2008 19:25:56 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:3925230a-7a23-4696-91ff-c92816af909c</guid>
      <link>http://blog.segment7.net/articles/2008/04/16/static-typing-for-ruby#comment-925</link>
    </item>
    <item>
      <title>"Static Typing for Ruby" by Charles Oliver Nutter</title>
      <description>&lt;p&gt;One point of clarification. You didn&amp;#8217;t mention Duby, but I&amp;#8217;m guessing you may have included it in your consideration of &amp;#8220;static typing add-ons for Ruby&amp;#8221;. The detail I&amp;#8217;d like to clarify is that Duby is not a static-typing add-on, nor is it Ruby. It just uses Ruby syntax.&lt;/p&gt;


	&lt;p&gt;And if Duby was not included in that consideration, nevermind :)&lt;/p&gt;</description>
      <pubDate>Thu, 17 Apr 2008 15:29:32 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:75f56dc1-77c2-4ed8-ace5-6c297d63e7ba</guid>
      <link>http://blog.segment7.net/articles/2008/04/16/static-typing-for-ruby#comment-924</link>
    </item>
    <item>
      <title>"Static Typing for Ruby" by Eric Hodel</title>
      <description>&lt;p&gt;Thanks Chris, whichever textile converter I have installed puked all over that.&lt;/p&gt;</description>
      <pubDate>Wed, 16 Apr 2008 17:59:09 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:f128e0f4-3103-4d6b-95af-f0ccdbc04ea9</guid>
      <link>http://blog.segment7.net/articles/2008/04/16/static-typing-for-ruby#comment-923</link>
    </item>
    <item>
      <title>"Static Typing for Ruby" by John Barnette</title>
      <description>&lt;p&gt;&lt;a href="http://tinyurl.com/6dkmob" rel="nofollow"&gt;http://tinyurl.com/6dkmob&lt;/a&gt; (this is a PDF)&lt;/p&gt;</description>
      <pubDate>Wed, 16 Apr 2008 17:58:02 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:581fdf5f-2f07-406e-90f9-50a28c2f78b7</guid>
      <link>http://blog.segment7.net/articles/2008/04/16/static-typing-for-ruby#comment-922</link>
    </item>
    <item>
      <title>"Static Typing for Ruby" by Chris Lloyd</title>
      <description>&lt;p&gt;HTML Escape fail.&lt;/p&gt;</description>
      <pubDate>Wed, 16 Apr 2008 17:10:09 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:934945a8-42b8-4c94-a308-b42856262216</guid>
      <link>http://blog.segment7.net/articles/2008/04/16/static-typing-for-ruby#comment-921</link>
    </item>
  </channel>
</rss>
