<?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>Talk Like A Duck: Tag matz</title>
    <link>http://talklikeaduck.denhaven2.com/articles/tag/matz</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>In Ruby, it's not the dog, it's the tricks!</description>
    <item>
      <title>A Chat with Matz, Classs Variable reversion, and A Mystery Explained</title>
      <description>&lt;img src="http://talklikeaduck.denhaven2.com/files/2007-11-02_ruby_conf_2007logo_200x_123.png" alt="Ruby Conf 2007logo 200x 123" height="123" width="200" style='border-width:1px; border-color:#444444; margin-bottom:30px; margin-right:30px;border-style:solid;float:left;'&gt;
I finally got to meet Matz in person today, and we had a nice little chat.
&lt;p&gt;I was pleased to learn that he follows this blog.  My readership might be small, but it's quality readership. One thing I told him was that as much as I love, and still love, Smalltalk, I really do feel that I love Ruby just a little bit more.&lt;/p&gt;
&lt;p&gt;We talked a bit about the upcoming stabilization of 1.9, which will be frozen as far as language and standard libary changes for the Christmas 2007 1.9.1 release, at which time transition from development to stable status. He has been backing out some of the differences between 1.8.x and 1.9.0. He told me that he had recently, or was soon to, revert the changes to the scoping of class variables.  It appears that class variables will continue to be shared between classes and subclasses.&lt;/p&gt;
&lt;p&gt;He also cleared up a technical ruby mystery that's been puzzling me for some time.&lt;/p&gt;
&lt;p&gt;About a year ago I wrote about a change in Ruby 1.9 which &lt;a href="http://talklikeaduck.denhaven2.com/articles/2006/10/09/a-subtle-change-to-mixin-semantics-in-ruby-1-9"&gt;cleaned up the semantics&lt;/a&gt; when modules included by a class are re-included in a subclass.  The mystery is that sometime after I wrote the article, in a subsequent revision of 1.9, this got dropped.  I never could find out why this happened, so today I took the opportunity to ask Matz in person.&lt;/p&gt;



&lt;p&gt;He agreed that the way that it worked temporarily was the right way for it to work, but it got dropped because YARV had difficulties with the change in implementing the &lt;strong&gt;super&lt;/strong&gt; keyword.&lt;/p&gt;
&lt;p&gt;We didn't go into further details, but here's my informed speculation on the situation.&lt;/p&gt;
&lt;p&gt;When you send a message to a Ruby object, what happens, at least notionally, is that a linked list of (pseudo)objects is searched to find the first one which contains a method with that name in its method hash. Let's call this the method lookup chain. The head of the chain is pointed to by the receiving objects klass field, and is either the singleton class of the object if it has one, or the Class of the object, links in the chain represent modules and classes in the ancestry of the object. If the end of the chain is reached a method_not_found message is generated and searched for beginning again from the beginning of the receiving objects method chain.&lt;/p&gt;
&lt;p&gt;Each link is either a class or a pseudo object marked as an "IClass" (for Included Class) whose method hash pointer points to the method hash of the Module it represents. Because module method hashes are shared in this way, changes modules methods will be visible to every class or module which includes the module immediately.&lt;/p&gt;
&lt;p&gt;When the 'receiver' is &lt;strong&gt;super&lt;/strong&gt;, the same kind of search occurs as for a send to &lt;strong&gt;self&lt;/strong&gt;, but instead of starting with the receivers method chain, we want to search starting with the link in the chain after the one in which the currently executing method was found.&lt;/p&gt;
&lt;p&gt;Smalltalk implementations typically reify methods as CompiledMethod objects which have an instance variable which refers to the class in which the method was defined. So a send to &lt;strong&gt;super&lt;/strong&gt; simply starts the search with the superclass of the currently executing CompiledMethods definition class.&lt;/p&gt;
&lt;p&gt;This approach doesn't work for Ruby because Modules can be included in multiple classes or modules, which means that methods defined in Modules can appear in multiple places in multiple method lookup chains.&lt;/p&gt;
&lt;p&gt;One way to find the right place to start searching for a method with &lt;strong&gt;super&lt;/strong&gt; as the receiver is to start from the beginning of &lt;strong&gt;self&lt;/strong&gt;s method lookup chain, search until we find the currently executing method, then start the &lt;strong&gt;super&lt;/strong&gt; search with the next link in the chain.  I believe that this is how Ruby works, except for that brief time in the evolution of 1.9.&lt;/p&gt;
&lt;p&gt;In Smalltalk you must name the message when you do a send to &lt;strong&gt;super&lt;/strong&gt;. In Ruby you can't.  Smalltalk, unlike Ruby, allows you to send a different message than the current one to &lt;strong&gt;super&lt;/strong&gt;. In Smalltalk, the keyword &lt;strong&gt;super&lt;/strong&gt; effectively means "&lt;strong&gt;self&lt;/strong&gt;, but resolve any messages starting with the superclass of the class which defined the currently executing method," while in Ruby it means something like, "the current message, but look for me after where you found the currently executing method."  This difference simplifies finding the current method in the chain.  We know we're looking for a method with the same name in both the first and second searches. Since each link in the chain has a hash of methods, it's generally faster to do a hash lookup on the name, and in the first stage of the search compare the value returned with the current method.&lt;/p&gt;
&lt;p&gt;This two-phase search for &lt;strong&gt;super&lt;/strong&gt; runs into a small snag when a modules method hash appears more than once in a given method lookup chain. The first stage &lt;strong&gt;super&lt;/strong&gt; search can find the wrong place in the chain.&lt;/p&gt;
&lt;p&gt;Here's some code similar to that in the earlier article.&lt;/p&gt;
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;notextile&gt;&lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;M&lt;/span&gt;
  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;foo&lt;/span&gt; &lt;span class="comment"&gt;#foo_m&lt;/span&gt;
    &lt;span class="ident"&gt;puts&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;foo in M1&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
    &lt;span class="keyword"&gt;super&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;

&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;C1&lt;/span&gt;
  &lt;span class="ident"&gt;include&lt;/span&gt; &lt;span class="constant"&gt;M&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;

&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;C2&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;C1&lt;/span&gt;
  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;foo&lt;/span&gt; &lt;span class="comment"&gt;#foo_c&lt;/span&gt;
    &lt;span class="ident"&gt;puts&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;foo in C2&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
    &lt;span class="keyword"&gt;super&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt; 

&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;C3&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;C2&lt;/span&gt;
  &lt;span class="ident"&gt;include&lt;/span&gt; &lt;span class="constant"&gt;M&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/notextile&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Admittedly this code is contrived, it's specifically crafted to expose the issue in the simplest way, C1, C2, and C3 would probably have other methods which don't need to be shown here.
&lt;p&gt;If every module inclusion in the above code created an IClass then the method chain for instances of C3 Would look like this:&lt;/p&gt;
&lt;img src="http://myskitch.com/rubyredrick/cam-20071103-014213.jpg" alt="Cam"&gt;
&lt;p&gt;The boxes with names inside represent the class objects, empty orange boxes represent IClass pseudo-objects, the blue box labeled M is the module object, and the blue labels represent the methods.&lt;/p&gt;
&lt;p&gt;Okay, now let's say we evaluate the expression:&lt;/p&gt;
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;notextile&gt;&lt;span class="constant"&gt;C3&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;foo&lt;/span&gt;&lt;/notextile&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol&gt;
	&lt;li&gt;We first search the method chain for a foo method and the first one we find is foo_m in the first IClass, so we invoke it.&lt;/li&gt;
	&lt;li&gt;We reach the &lt;strong&gt;super&lt;/strong&gt; in foo_m, so we start at the beginning of the method chain to find it which we do in the first IClass, since this is a send to &lt;strong&gt;super&lt;/strong&gt;, we then look for the next mathod named foo, and we find foo_c in class C2, so we invoke it.&lt;/li&gt;
	&lt;li&gt;We reach the &lt;strong&gt;super&lt;/strong&gt; in foo_c, so we start at the beginning of the method chain to find it which we do in the first IClass, since this is a send to &lt;strong&gt;super&lt;/strong&gt;, we then look for the next mathod named foo, and we find foo_c in class C2, so we invoke that.&lt;/li&gt;
	&lt;li&gt;We reach the &lt;strong&gt;super&lt;/strong&gt; in foo_c, so we start at the beginning of the method chain to find it which we do in the first IClass, since this is a send to &lt;strong&gt;super&lt;/strong&gt;, we then look for the next mathod named foo, and we find foo_c in class C2, so we invoke that.&lt;/li&gt;
	&lt;li&gt;Houston, we have a problem!&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So, including IClasses for a module more than once can lead to an infinite loop when there's a &lt;strong&gt;super&lt;/strong&gt;, if the two-part re-search is used.&lt;/p&gt;
&lt;p&gt;And this is most probably the reason why the code to include a module checks to see if the module is already included and doesn't actually re-include it in this, admittedly rare case.&lt;/p&gt;
&lt;p&gt;So late last year, some other mechanism must have been being used to find the start of the super method chain, to allow real module re-inclusion. Perhaps, whenever a method was invoked, a pointer to the Class or IClass where it was found was placed on the execution stack so that it could be found if needed to resolve &lt;strong&gt;super&lt;/strong&gt;, perhaps some other mechanism was used.&lt;/p&gt;
&lt;p&gt;Whatever method was used, it was apparently incompatible, or hard to implement efficiently with YARV, so when YARV became a standard part of 1.9, the old module inclusion logic came back.&lt;/p&gt;
&lt;p&gt;Oh well, being able to re-include really makes the semantics of Module inclusion clearer, seems a shame, albeit perhaps a rather small one.&lt;/p&gt;</description>
      <pubDate>Sat, 03 Nov 2007 02:51:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:d3f1cb74-7196-4237-b529-92666bfc8c2a</guid>
      <author>Rick DeNatale</author>
      <link>http://talklikeaduck.denhaven2.com/articles/2007/11/03/a-chat-with-matz-classs-variable-reversion-and-a-mystery-explained</link>
      <category>ruby</category>
      <category>smalltalk</category>
      <category>railsconf2007</category>
      <category>railsconf</category>
      <category>matz</category>
      <trackback:ping>http://talklikeaduck.denhaven2.com/articles/trackback/481</trackback:ping>
    </item>
    <item>
      <title>Town Meeting with Matz at RubyConf 2007</title>
      <description>&lt;div style="float:left;"&gt;
&lt;img src="http://talklikeaduck.denhaven2.com/files/2007-11-02_matz_townhall_at_rubyconf_2007.png" alt="Matz Townhall at RubyConf 2007" height="275" width="184" style='border-width:1px; border-color:#444444; margin-bottom:30px; margin-right:30px;border-style:solid;'&gt;&lt;p&gt;Photo by Nathaniel Talbott.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This was not quite the largest audience Matz has faced there were about 500 in attendance at this evening's "Town Hall Meeting", he asid that he had spoken to a group of over 1000 in Japan, but that was not to an exclusively Ruby audience.&lt;/p&gt;

&lt;p&gt;I captured most of the questions and answers as best as I could.  Any errors of paraphrasing are mine:&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;Q1&lt;/dt&gt;&lt;dt&gt;What about backwards compatibility. My program broke when Ruby 1.9 changed File.exists? to File.exist?&lt;/dt&gt;

&lt;dt&gt;A1&lt;/dt&gt;&lt;dd&gt;We try to keep the language as backwards compatible as possible, but File.exists? was an old method inconsistent with the naming of predicates. &lt;/dd&gt;

&lt;dt&gt;Q2&lt;/dt&gt;&lt;dd&gt;(From an Engineer from TI looking at putting Ruby into new calculators)  I don't like the licence on the regexp library function in 1.8. The regexp engine in 1.9 isn't "encumbered" by the GPL?! When will 1.9 be out.&lt;/dd&gt;

&lt;dt&gt;A2&lt;/dt&gt;&lt;dd&gt;Ruby 1.9.1 will be out by Christmas 2007, but might not be as stable as we want.&lt;/dd&gt;



&lt;/dl&gt;
&lt;p&gt;(Note from Rick) I'd talked earlier to Matz about this. The Christmas release will freeze the language and library APIs, it's the implementation which is expected to change to fix bugs and improve performance. That's what he means by "not as stable."&lt;/p&gt;
&lt;dt&gt;Q3&lt;/dt&gt;&lt;dd&gt;We had a problem with our app due to integer performance, why not change Fixnum to not go to Bignums automatically?&lt;/dd&gt;

&lt;dt&gt;A3&lt;/dt&gt;&lt;dd&gt;We won't "bend the language" for performance.  Big Applause.&lt;/dd&gt;

&lt;dt&gt;Q4&lt;/dt&gt;&lt;dd&gt;What do you think about the competition from JRuby, Rubinius, IronRuby?&lt;/dd&gt;

&lt;dt&gt;A4&lt;/dt&gt;&lt;dd&gt;Having the alternative implementations is wonderful. They open up a new world for people who couldn't use ruby for various reasons.&lt;/dd&gt;

&lt;dt&gt;Q5&lt;/dt&gt;&lt;dd&gt;Is working on Ruby still something that makes you happy? What's the most enjoyable thing about it.&lt;/dd&gt;

&lt;dt&gt;A5&lt;/dt&gt;&lt;dd&gt;I started on Ruby in 1993 with the goal of enjoying myself, I enjoy programming in Ruby, I enjoy designing it, and I enjoy implementing it.  I still enjoy it very much.&lt;/dd&gt;

&lt;dt&gt;Q6&lt;/dt&gt;&lt;dd&gt;What's the Ruby community and presence like in Japan.&lt;/dd&gt;

&lt;dt&gt;A6&lt;/dt&gt;&lt;dd&gt;It's pretty much the same as the people here at RubyConf. They're nice people, fun, and interested in new technology.  More people are actually earning their living from/with Ruby in America than Japan.&lt;/dd&gt;

&lt;dt&gt;Q7&lt;/dt&gt;&lt;dd&gt;Does the increasing use of Ruby here in the States cause you to feel pressure? For example the TI question about licensing?&lt;/dd&gt;

&lt;dt&gt;A7&lt;/dt&gt;&lt;dd&gt;I try to stay away from the enterprise contracting issues.&lt;/dd&gt;

&lt;dt&gt;Q8&lt;/dt&gt;&lt;dd&gt;What Editor do you Use?&lt;/dd&gt;

&lt;dt&gt;A8&lt;/dt&gt;&lt;dd&gt;Emacs. Mixed reaction.&lt;/dd&gt;

&lt;dt&gt;Q9&lt;/dt&gt;&lt;dd&gt;(Charles Nutter) When can we expect a final 1.9 spec?&lt;/dd&gt;

&lt;dt&gt;A9&lt;/dt&gt;&lt;dd&gt;The features are almost fixed. I'm now in the process of auditing 1.9 changes. I'm going to reverse some of the 1.9 changes in a week or two. By the middle of this month (November 2007) the features will be pretty much stable.&lt;/dd&gt;

&lt;dt&gt;Q10&lt;/dt&gt;&lt;dd&gt;In the matter of Ruby, do you consider yourself a Scientist, or an Artist and why?&lt;/dd&gt;

&lt;dt&gt;A10&lt;/dt&gt;&lt;dd&gt;A Hobbyist.  Ruby started out as my own toy language, I expected just a few users of the language. Now we have 500 ruby users in this room. I don't know how to count the number in the world, perhaps hundreds of thousands.&lt;/dd&gt;

&lt;dt&gt;Q11&lt;/dt&gt;&lt;dd&gt;Would you ever consider exposing the parse tree to ruby programs?&lt;/dd&gt;

&lt;dt&gt;A11&lt;/dt&gt;&lt;dd&gt;The parse tree is pretty implementation dependent so exposing it as a spec would be tough for us to support in the future.&lt;/dd&gt;
      
&lt;dt&gt;Q12&lt;/dt&gt;&lt;dd&gt;What other languages are you looking at now?&lt;/dd&gt;

&lt;dt&gt;A12&lt;/dt&gt;&lt;dd&gt;Erlang, I don't like the syntax but there are some interesting ideas in it. &lt;/dd&gt;

&lt;dt&gt;Q13&lt;/dt&gt;&lt;dd&gt;Someone said that there wasn't much room to improve the implementation of Ruby/YARV, but a Smalltalk programmer told me about two techniques used by Smalltalk VMs, Polymorphic Inline Caching and Dynamic Compilation are they applicable?&lt;/dd&gt;

&lt;dt&gt;A13&lt;/dt&gt;&lt;dd&gt;Did &lt;strong&gt;I&lt;/strong&gt; say that there was no room for improvement?  We know about such techniques and are looking at them for Ruby.&lt;/dd&gt;

&lt;dt&gt;Q14&lt;/dt&gt;&lt;dd&gt;Rails has done a lot to boost the usage of Ruby. Do you see other areas which might provide similar frameworks/things to boost Ruby.&lt;/dd&gt;

&lt;dt&gt;A14&lt;/dt&gt;&lt;dd&gt;We're looking at things to improve processing large data sets on multi-core platforms.&lt;/dd&gt;

&lt;dt&gt;Q15&lt;/dt&gt;&lt;dd&gt;Some people in the Java world say that Ruby is great for fast development, fast compile times, but needing static typing and other less dynamic features to scale up, is this a problem for Ruby.&lt;/dd&gt;

&lt;dt&gt;A15&lt;/dt&gt;&lt;dd&gt;Well there are things which make Ruby harder to use with extremely large teams. Java still shines in large scale enterprise development, but the rules are changing, there's more emphasis on smaller quicker projects, and Ruby shines there. We will probably look at some things like better name scoping to help with larger team projects but that won't be until the version of Ruby after 1.9.&lt;/dd&gt;

&lt;dt&gt;A16&lt;/dt&gt;&lt;dd&gt;The beauty of Ruby to me is that it's "just one step ahead" of the programmer compared to say lisp, erlang, which are harder to understand.&lt;/dd&gt;

&lt;dt&gt;Q17&lt;/dt&gt;&lt;dd&gt;What's your second favorite programming language?&lt;/dd&gt;
&lt;dt&gt;A18&lt;/dt&gt;&lt;dd&gt;Several&lt;/dd&gt;

&lt;dt&gt;Q18&lt;/dt&gt;&lt;dd&gt;What would you remove from Ruby, is there anything that doesn't belong?&lt;/dd&gt;
&lt;dt&gt;Q18&lt;/dt&gt;&lt;dd&gt;Matz didn't seem to be able to think of anything.&lt;/dd&gt;

&lt;dt&gt;Q19&lt;/dt&gt;&lt;dd&gt;Have you looked at the Toyota Lean Process?  Are you familiar with it? Is it applicable to Ruby/Software development?&lt;/dd&gt;

&lt;dt&gt;A19&lt;/dt&gt;&lt;dd&gt;It's interesting that there are so many parallels between auto manufacturing and softwere development.&lt;/dd&gt;

&lt;dt&gt;Q20&lt;/dt&gt;&lt;dd&gt;Are continuations in or out of 1.9.&lt;/dd&gt;

&lt;dt&gt;A20&lt;/dt&gt;&lt;dd&gt;You now need to require a library file, so they are out of the core language, but they're not completely out.&lt;/dd&gt;

&lt;dt&gt;Q21&lt;/dt&gt;&lt;dd&gt;What about parallelism?&lt;/dd&gt;

&lt;dt&gt;A21&lt;/dt&gt;&lt;dd&gt;We are looking at options like running multiple independent VMs on threads in the same process, with shared code.&lt;/dd&gt;

&lt;dt&gt;Q22&lt;/dt&gt;&lt;dd&gt;You had talked before about selector namespaces&lt;/dd&gt;

&lt;dt&gt;A22&lt;/dt&gt;&lt;dd&gt;It's tough to implement but we are looking at it for Ruby 2.0.&lt;/dd&gt;

&lt;dt&gt;Q23&lt;/dt&gt;&lt;dd&gt;Do you see a difference in the coding style between American and Japanese rubyists?&lt;/dd&gt;

&lt;dt&gt;A23&lt;/dt&gt;&lt;dd&gt;I don't really focus on it. Although recently code 'golfing' has seemed to become popular in Japan.&lt;/dd&gt;

&lt;dt&gt;Q24&lt;/dt&gt;&lt;dd&gt;One of the key features of the IO language is that it has no keywords.  Have you looked at that as a potential goal for future versions of Ruby.&lt;/dd&gt;

&lt;dt&gt;A24&lt;/dt&gt;&lt;dd&gt;IO is interesting, but that's not the way that Ruby is going.&lt;/dd&gt;
&lt;/dl&gt;&lt;/dt&gt;</description>
      <pubDate>Fri, 02 Nov 2007 20:50:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:7df25532-7357-4d55-ae50-25d1b168ea7d</guid>
      <author>Rick DeNatale</author>
      <link>http://talklikeaduck.denhaven2.com/articles/2007/11/02/town-meeting-with-matz-at-rubyconf-2007</link>
      <category>ruby</category>
      <category>railsconf2007</category>
      <category>railsconf</category>
      <category>matz</category>
      <trackback:ping>http://talklikeaduck.denhaven2.com/articles/trackback/480</trackback:ping>
    </item>
  </channel>
</rss>
