<?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 som</title>
    <link>http://talklikeaduck.denhaven2.com/articles/tag/som</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>In Ruby, it's not the dog, it's the tricks!</description>
    <item>
      <title>A Meeting with &amp;quot;Gill Bates&amp;quot;</title>
      <description>&lt;p&gt;A recent thread on ruby-core which touches on the issues of subclassing
prompts me to tell another war story.&lt;/p&gt;
&lt;p&gt;Back in the late-1980s to early 1990s, the software industry was starting to warm to the possibilities of object-orientation.  
I&amp;#8217;d gotten to be seen as one of the experts on OO inside &lt;span class="caps"&gt;IBM&lt;/span&gt; so I found myself
in a series of interesting meetings, but inside &lt;span class="caps"&gt;IBM&lt;/span&gt; and with other 
companies.&lt;/p&gt;
&lt;p&gt;That&amp;#8217;s how I found myself at the headquarters of 
a well-known company in the Seattle area 
which at that time was one of &lt;span class="caps"&gt;IBM&lt;/span&gt;&amp;#8217;s major partners.
This company was the major supplier of &lt;span class="caps"&gt;IBM&lt;/span&gt;&amp;#8217;s operating systems
for personal computers.  I don&amp;#8217;t want to give too many hints, so I&amp;#8217;ll give a
pseudonym to the &lt;span class="caps"&gt;CEO&lt;/span&gt;, let&amp;#8217;s just call him &amp;#8220;Gill Bates&amp;#8221;, and I&amp;#8217;ll refer to the
company as &amp;#8220;BigSoftware&amp;#8221; or &amp;#8220;BS&amp;#8221; for short.&lt;/p&gt;

&lt;p&gt;Now some of the guys I
used to work with at &lt;span class="caps"&gt;IBM&lt;/span&gt; might remember a co-worker in &lt;span class="caps"&gt;IBM&lt;/span&gt; Cary, and then &lt;span class="caps"&gt;RTP&lt;/span&gt;,
named Gil Bates, different guy.&lt;/p&gt;  
&lt;p&gt;The meeting was to discuss
the BS plans for a new operating system with an object-oriented 
implementation
and application programming interface. 
A small team of BS engineers presented to
a small team of IBMers.  I found myself sitting across a conference table from
the presenters and right next to Gill.&lt;/p&gt;
&lt;h2&gt;Frameworks, Frameworks, Everywhere&lt;/h2&gt;
&lt;p&gt;Let me step back a bit and give a little techno-historical perspective
for those who weren&amp;#8217;t involved in software in the late 1980s/early 1990s.&lt;/p&gt;
&lt;p&gt;One of the things which was exciting people at that time was the emergence of
application frameworks.
MacApp had been around a bit, and had gotten some publicity.  This was a
framework written in Object Pascal which made writing Macintosh applications
considerably easier. MacApp provided inheritable classes
which implemented a vanilla application conforming to the Mac UI guidelines.
Writing a MacApp application consisted of subclassing the framework classes
and adding the behavior which made the app what you wanted it to be.&lt;/p&gt;
&lt;p&gt;MacApp spawned other frameworks, ET++ was a port to C++ done in 
Zurich by a team, which included Erich Gamma, if I recall correctly.&lt;/p&gt;
&lt;p&gt;MacApp itself later was ported to C++, which led to Apple&amp;#8217;s ill-fated Pink
project.  I&amp;#8217;ll probably tell a war-story or two about Pink here sometime.&lt;/p&gt;
&lt;p&gt;Of course the framework notion has long legs, for example Rails is such a
framework for writing web-based applications.&lt;/p&gt;
&lt;p&gt;Back then, the idea of applying the idea not just to applications but to
operating systems seemed natural to many.  MacApp and its ilk contained
object-oriented wrappers to OS apis.  Why not just make the whole OS a
framework?&lt;/p&gt;  
&lt;p&gt;As an OO evangelist I&amp;#8217;d been caught up in this as well, selling the idea of
frameworks.  I was still pushing for application frameworks, but the idea of a
framework-based OS seemed pretty neat until I started thinking harder about it.
&lt;/p&gt;
&lt;h2&gt;The Blessing and Curse of Inheritance&lt;/h2&gt;
&lt;p&gt;Object Orientation to my mind is about encapsulation.  The implementation of
an object is hidden from the users of the object.  Inheritance is a powerful
implementation technique, but it breaks the encapulation between superclass, class, and subclass.  Like it or not, subclasses need to be written with knowledge
of,
and track changes to,
the implementation of their superclass.  That&amp;#8217;s okay as long as the 
superclass remains relatively stable.&lt;/p&gt;
&lt;p&gt;The problem is that you can&amp;#8217;t expect that kind of stability over time.  As
the framework evolves, new methods and features get added to the framework 
provided superclasses, and worse from the point of view of the framework
subclasser, the inheritance relationships between the framework classes often
change.  It&amp;#8217;s the natural result of refactoring.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;d played with about three releases of MacApp, and noticed that with each
release, I needed to rewrite substantial parts of my applications if I wanted
to step up to the new version.  This was okay in that, 
since the MacApp framework classes became part of my application, 
the application was a self-contained
whole, and would continue to run as long as I didn&amp;#8217;t rebuild it with the new
framework version.&lt;/p&gt;
&lt;p&gt;Dealing with the inevitable refactorings is feasible if you have control 
all of the code being refactored, or at least can delay refactoring by 
ignoring new versions of code not under your control.  
The problem becomes much more difficult
when the operating system interfaces require your code to inherit from the 
system.  New operating systems will break existing applications.&lt;/p&gt;
&lt;p&gt;Inheritance is a mechanism for sharing code &lt;span class="caps"&gt;DNA&lt;/span&gt;.  
In that sense it&amp;#8217;s like sex.
It&amp;#8217;s best when it&amp;#8217;s restricted to consenting adults, practicing using
safe techniques, and aware of the potential consequences.&lt;/p&gt;
&lt;h2&gt;The State of the Art circa 1990&lt;/h2&gt;
&lt;p&gt;The difficulty of maintaining compatibility between releases is exacerbated
when the techniques used to provide inheritance are statically bound.  At the
time of my tale, it was conventional wisdom that in order to get reasonable
performance out of an object oriented program the classical C++ approach was
the only way to go.  This involved using arrays of pointers to the method
functions, called virtual function tables, and mapping method names to an integer sequence from 1 to the number
of methods needed. For a given class, the number of the first method it
introduced (i.e. a method which was not just an override of an inherited method)
would be one more than the maximum number assigned to its superclass&amp;#8217;s methods.
These numbers were determined statically at compile time, and needed to be known
when a call to a method was compiled.&lt;/p&gt;
&lt;p&gt;This meant that a simple act such as adding a new method definition in a
class would require recompilation of not just that class, 
but all of it&amp;#8217;s subclasses,
and any code which called a method on any instance of the class or its 
subclasses.  Besides making for long build times, it also meant that such a
change would break binary compatibility even in cases where subclassing or
client code which didn&amp;#8217;t use the new method and so didn&amp;#8217;t need to have its
source code changed.&lt;/p&gt;
&lt;p&gt;Inside &lt;span class="caps"&gt;IBM&lt;/span&gt;, something called the System Object Model was being advocated.
This was an attempt to make the C++ implementation just described a little more
flexible to at least partially address this problem, an issue which was dubbed
the &amp;#8220;fragile base class&amp;#8221; problem.&lt;/p&gt;
&lt;p&gt;But the number of refactorings which can be successfuly addressed just
by loosening up the method calling mechanisms is a small subset of the
refactorings which normally occur over the life-cycle of a framework. 
Early binding issues or not, even with a dynamic language like Smalltalk
or Ruby, maintaining interface compatibility over time is a very difficult
problem.&lt;/p&gt;
&lt;p&gt;Rails, like MacApp, addresses this by letting applications be frozen to
a particular version of the Framework.&lt;/p&gt;
&lt;h2&gt;Back to the Conference Room&lt;/h2&gt;
&lt;p&gt;So as you&amp;#8217;ll recall, I found myself sitting next to &amp;#8220;Gill Bates&amp;#8221; while his 
senior architects presented their framework based operating system to be written
in C++.  I gently introduced the problems I just described, and it took a while
for it to sink in.
&lt;p&gt;I kept re-asking my questions as they came up with inadequate answers.  
Meanwile I noticed that, sitting next to me, &amp;#8220;Gill&amp;#8221; was starting to rock
back and forth in his chair.&lt;/p&gt;
&lt;p&gt;Finally, I said:&lt;/p&gt;
&lt;blockquote&gt;I just don&amp;#8217;t understand how you are going to maintain compatibility
after you refactor the framework for the second release.&lt;/blockquote&gt;
&lt;p&gt;The reply was:&lt;/p&gt;
&lt;blockquote&gt;We have our &lt;strong&gt;best people&lt;/strong&gt; designing the system, 
we &lt;strong&gt;won&amp;#8217;t have to refactor.&lt;/strong&gt;&lt;/blockquote&gt;
&lt;p&gt;At that point, I suggested that the best people would recogize the
inevitability of refactoring.  At which &amp;#8220;Gill&amp;#8221; finally chipped in by saying
to his presenter:&lt;/p&gt;
&lt;blockquote&gt;You guys don&amp;#8217;t explain our stuff very well.&lt;/blockquote&gt;</description>
      <pubDate>Fri, 15 Jun 2007 16:27:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:aedea30e-c248-404f-a486-b4245b9b10ab</guid>
      <author>Rick DeNatale</author>
      <link>http://talklikeaduck.denhaven2.com/articles/2007/06/15/a-meeting-with-gill-bates</link>
      <category>war_stories</category>
      <category>som</category>
      <category>fragilecode</category>
      <category>inheritance</category>
      <category>frameworks</category>
    </item>
  </channel>
</rss>
