<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Is Inheritance overrated ? Needed even?</title>
	<atom:link href="http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/feed/" rel="self" type="application/rss+xml" />
	<link>http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/</link>
	<description>Thoughts and factoids from the Real Shyam. You know, unlike those fake ones!!</description>
	<lastBuildDate>Wed, 21 Apr 2010 17:05:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Tim</title>
		<link>http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/comment-page-1/#comment-185</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Thu, 01 Oct 2009 08:13:30 +0000</pubDate>
		<guid isPermaLink="false">http://theshyam.com/?p=172#comment-185</guid>
		<description>Hi,

You really should check out functional programming languages based on your comment on favoring composition over inheritance.  (besides that, it is ideal for both very large and very small scale programs, and everything in between) Modern functional languages, such as Haskell have very sophisticated ways of dealing with polymorphic types, and good module systems, and make composition very central to coding practice.  In Haskell&#039;s case, they separate I/O from functions (by using the I/O Monad), which ensures that function composition remains pure in every case.  If you just want some mix of higher order functions and mixed OO techniques, Scala is complex, but might suit your needs. (plus, it&#039;s on the JVM if you&#039;re a java programmer)</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>You really should check out functional programming languages based on your comment on favoring composition over inheritance.  (besides that, it is ideal for both very large and very small scale programs, and everything in between) Modern functional languages, such as Haskell have very sophisticated ways of dealing with polymorphic types, and good module systems, and make composition very central to coding practice.  In Haskell&#8217;s case, they separate I/O from functions (by using the I/O Monad), which ensures that function composition remains pure in every case.  If you just want some mix of higher order functions and mixed OO techniques, Scala is complex, but might suit your needs. (plus, it&#8217;s on the JVM if you&#8217;re a java programmer)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Lindal</title>
		<link>http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/comment-page-1/#comment-173</link>
		<dc:creator>John Lindal</dc:creator>
		<pubDate>Wed, 23 Sep 2009 17:54:30 +0000</pubDate>
		<guid isPermaLink="false">http://theshyam.com/?p=172#comment-173</guid>
		<description>To Troy&#039;s point, I ended up doing exactly this when I implemented &lt;a href=&quot;http://github.com/jafl/java_actor&quot; rel=&quot;nofollow&quot;&gt;Erlang Actors&lt;/a&gt; in Java.  In order to make the threading model configurable at run time (rather than having to inherit from a base class which implemented a particular threading model), I had to delegate the hard way.  Luckily, the number of methods was quite small.

If I remember correctly, Objective C has delegation built in.  You can say, &lt;q&gt;If you don&#039;t find the requested method in me, try this other object.&lt;/q&gt;</description>
		<content:encoded><![CDATA[<p>To Troy&#8217;s point, I ended up doing exactly this when I implemented <a href="http://github.com/jafl/java_actor" rel="nofollow">Erlang Actors</a> in Java.  In order to make the threading model configurable at run time (rather than having to inherit from a base class which implemented a particular threading model), I had to delegate the hard way.  Luckily, the number of methods was quite small.</p>
<p>If I remember correctly, Objective C has delegation built in.  You can say, <q>If you don&#8217;t find the requested method in me, try this other object.</q></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Software Engineering vs Software Artistry &#171; The Shyam!</title>
		<link>http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/comment-page-1/#comment-139</link>
		<dc:creator>Software Engineering vs Software Artistry &#171; The Shyam!</dc:creator>
		<pubDate>Tue, 08 Sep 2009 21:09:36 +0000</pubDate>
		<guid isPermaLink="false">http://theshyam.com/?p=172#comment-139</guid>
		<description>[...] never expected my last post about whether Inheritance was needed or could be done away with to spark such a furore. But spark a furore it did, especially at the Java DZone lobby. Maybe [...]</description>
		<content:encoded><![CDATA[<p>[...] never expected my last post about whether Inheritance was needed or could be done away with to spark such a furore. But spark a furore it did, especially at the Java DZone lobby. Maybe [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Troy Gilbert</title>
		<link>http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/comment-page-1/#comment-105</link>
		<dc:creator>Troy Gilbert</dc:creator>
		<pubDate>Fri, 21 Aug 2009 04:48:35 +0000</pubDate>
		<guid isPermaLink="false">http://theshyam.com/?p=172#comment-105</guid>
		<description>You&#039;re absolutely right, inheritance is most definitely used incorrectly more often than not because of its convenience syntactically, and this is a huge problem overlooked (or left unaddressed) by many language designers (particularly those in the curly-brace lineage).

The &quot;ideal&quot; object-oriented design has objects speaking to each other only through known interfaces (with the generic &quot;send message&quot; method being an assumed universal amongst all objects). It&#039;s the whole &quot;programming by contract&quot; argument.

Unfortunately, the C++ designers (or whomever they were borrowing it from) were very implementation-focused and gave us *inheritance*. It worked well (i.e. computationally efficient) to have a &quot;base class&quot;, etc. But a better solution would be to have only interfaces (contracts).

With the curly-brace languages, you can certainly practice a pure-interface approach with your own class libraries. The pain and suffering is in shared implementations. A huge percentage of the time when you have sub-types you want to suck in the implementation for part of an interface that&#039;s common with the parent type. Inheritance does this (and implies an interface), but it&#039;s a sledgehammer.

If curly-brace languages had the native notion of *composition*, not just containment, we&#039;d be in business. I can&#039;t remember which language I was working in at the time, but I seriously pushed hard on introducing composition syntax:

&lt;code&gt;
class MyObject implements IReadWriteXml
{
	private var _xmlParser:XmlParser;
	interface IReadWriteXml to _xmlParser;
}
&lt;/code&gt;

The above should be pretty obvious, with the suggested line translating to &quot;forward all method calls on MyObject that are defined by the IReadWriteXml interface to _xmlParser.&quot; Instead, we have to do this:

&lt;code&gt;
class MyObject implements IReadWriteXml
{
	private var _xmlParser:XmlParser;
	public function readXml(xml:XML):void { _xmlParser.readXml(xml); }
	public function writeXml():XML { return _xmlParser.writeXml(); }
}
&lt;/code&gt;

And that&#039;s just a trivial example. This is exactly the kind of boiler plate code that higher level languages are supposed to eliminate.

Multiple prototypes (instead of classes) is another solution, though less precise because it wouldn&#039;t specify which interfaces should be forwarded to which prototype objects. And I don&#039;t know if any languages are multi-prototype.

As you can see, I&#039;ve been thinking about this language nuisance for damn near a decade, and I know I&#039;m not the only one. Almost every good, data-driven system I&#039;ve code has this very feature, even if only implicitly. Composition is king (for all the reasons you stated) -- inheritance is a crutch, a necessary evil, not because it solves problems at the computer science level, but because it solves problems at the implementation level, and only because of the constraints our tools invented and enforce!</description>
		<content:encoded><![CDATA[<p>You&#8217;re absolutely right, inheritance is most definitely used incorrectly more often than not because of its convenience syntactically, and this is a huge problem overlooked (or left unaddressed) by many language designers (particularly those in the curly-brace lineage).</p>
<p>The &#8220;ideal&#8221; object-oriented design has objects speaking to each other only through known interfaces (with the generic &#8220;send message&#8221; method being an assumed universal amongst all objects). It&#8217;s the whole &#8220;programming by contract&#8221; argument.</p>
<p>Unfortunately, the C++ designers (or whomever they were borrowing it from) were very implementation-focused and gave us *inheritance*. It worked well (i.e. computationally efficient) to have a &#8220;base class&#8221;, etc. But a better solution would be to have only interfaces (contracts).</p>
<p>With the curly-brace languages, you can certainly practice a pure-interface approach with your own class libraries. The pain and suffering is in shared implementations. A huge percentage of the time when you have sub-types you want to suck in the implementation for part of an interface that&#8217;s common with the parent type. Inheritance does this (and implies an interface), but it&#8217;s a sledgehammer.</p>
<p>If curly-brace languages had the native notion of *composition*, not just containment, we&#8217;d be in business. I can&#8217;t remember which language I was working in at the time, but I seriously pushed hard on introducing composition syntax:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:425px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">class MyObject implements IReadWriteXml<br />
{<br />
&nbsp; private var _xmlParser:XmlParser;<br />
&nbsp; interface IReadWriteXml to _xmlParser;<br />
}</div></td></tr></tbody></table></div>
<p>The above should be pretty obvious, with the suggested line translating to &#8220;forward all method calls on MyObject that are defined by the IReadWriteXml interface to _xmlParser.&#8221; Instead, we have to do this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:425px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">class MyObject implements IReadWriteXml<br />
{<br />
&nbsp; private var _xmlParser:XmlParser;<br />
&nbsp; public function readXml(xml:XML):void { _xmlParser.readXml(xml); }<br />
&nbsp; public function writeXml():XML { return _xmlParser.writeXml(); }<br />
}</div></td></tr></tbody></table></div>
<p>And that&#8217;s just a trivial example. This is exactly the kind of boiler plate code that higher level languages are supposed to eliminate.</p>
<p>Multiple prototypes (instead of classes) is another solution, though less precise because it wouldn&#8217;t specify which interfaces should be forwarded to which prototype objects. And I don&#8217;t know if any languages are multi-prototype.</p>
<p>As you can see, I&#8217;ve been thinking about this language nuisance for damn near a decade, and I know I&#8217;m not the only one. Almost every good, data-driven system I&#8217;ve code has this very feature, even if only implicitly. Composition is king (for all the reasons you stated) &#8212; inheritance is a crutch, a necessary evil, not because it solves problems at the computer science level, but because it solves problems at the implementation level, and only because of the constraints our tools invented and enforce!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Allen</title>
		<link>http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/comment-page-1/#comment-104</link>
		<dc:creator>Chris Allen</dc:creator>
		<pubDate>Fri, 21 Aug 2009 03:54:51 +0000</pubDate>
		<guid isPermaLink="false">http://theshyam.com/?p=172#comment-104</guid>
		<description>I think it&#039;s a good idea in principal. I&#039;ve always favored composition over inheritance for all the reasons you mentioned, and would like to basically remove the ability to have our developers even do inheritance except for very unique cases. The only time I think it&#039;s truly useful is when using an Abstract class. The whole idea of having to delegate to objects within your code for things you want to all other classes like it to do seems a bit kludgey. But, hey, like you said above, there is a way around it. And yeah, maybe it&#039;s better. But abstract classes are convenient and not that bad as long as you don&#039;t make the inheritance chain any longer than one level.

So, is it feasible? Yes. Would you be making some things harder, probably. Anyway, this is the first I&#039;ve heard of Noop, I will have to check it out. And thanks for the interesting post.</description>
		<content:encoded><![CDATA[<p>I think it&#8217;s a good idea in principal. I&#8217;ve always favored composition over inheritance for all the reasons you mentioned, and would like to basically remove the ability to have our developers even do inheritance except for very unique cases. The only time I think it&#8217;s truly useful is when using an Abstract class. The whole idea of having to delegate to objects within your code for things you want to all other classes like it to do seems a bit kludgey. But, hey, like you said above, there is a way around it. And yeah, maybe it&#8217;s better. But abstract classes are convenient and not that bad as long as you don&#8217;t make the inheritance chain any longer than one level.</p>
<p>So, is it feasible? Yes. Would you be making some things harder, probably. Anyway, this is the first I&#8217;ve heard of Noop, I will have to check it out. And thanks for the interesting post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frameworks vs. Toolkits &#124; BIT-101 Blog</title>
		<link>http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/comment-page-1/#comment-103</link>
		<dc:creator>Frameworks vs. Toolkits &#124; BIT-101 Blog</dc:creator>
		<pubDate>Fri, 21 Aug 2009 02:19:36 +0000</pubDate>
		<guid isPermaLink="false">http://theshyam.com/?p=172#comment-103</guid>
		<description>[...] http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/ [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/" rel="nofollow">http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/</a> [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
