<?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: Monkey Patching Core Functionality == BAD, BAD, BAD</title>
	<atom:link href="http://kurt.karmalab.org/2008/04/24/monkey-patching-core-classes-bad/feed/" rel="self" type="application/rss+xml" />
	<link>http://kurt.karmalab.org/2008/04/24/monkey-patching-core-classes-bad/</link>
	<description>Schrade.Blog</description>
	<lastBuildDate>Fri, 09 Jul 2010 06:07:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Chris McGrath</title>
		<link>http://kurt.karmalab.org/2008/04/24/monkey-patching-core-classes-bad/comment-page-1/#comment-233</link>
		<dc:creator>Chris McGrath</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">urn:uuid:{a.guid}#comment-233</guid>
		<description>I was bitten by this too when upgrading haml, I pity the fools without tests!</description>
		<content:encoded><![CDATA[<p>I was bitten by this too when upgrading haml, I pity the fools without tests!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan Leclercq</title>
		<link>http://kurt.karmalab.org/2008/04/24/monkey-patching-core-classes-bad/comment-page-1/#comment-234</link>
		<dc:creator>Stephan Leclercq</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">urn:uuid:{a.guid}#comment-234</guid>
		<description>Not even unit tests will help you in that case. A perfectly well written module will work in one application (including in your test fixture) and break in another !

I pity the fools using any language that allows such stupid constructs.</description>
		<content:encoded><![CDATA[<p>Not even unit tests will help you in that case. A perfectly well written module will work in one application (including in your test fixture) and break in another !</p>
<p>I pity the fools using any language that allows such stupid constructs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michaelw</title>
		<link>http://kurt.karmalab.org/2008/04/24/monkey-patching-core-classes-bad/comment-page-1/#comment-235</link>
		<dc:creator>michaelw</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">urn:uuid:{a.guid}#comment-235</guid>
		<description>@Stephan:
How is that different from subclassing a Java class, then overwriting a method (say, equals), with a version that violates its contract?  Pretty hard to detect automatically, and it happens all the time in the wild.

I am far from defending monkey patching, but I&#039;d rather have a language which is unsafe in places than one which is safe to the point that I can&#039;t get anything done.

As for the particular problem instance, perhaps the Ruby runtime could warn when it overrides a method, and (unless permitted by some configuration option) bail out if it detects overriding of core functionality.</description>
		<content:encoded><![CDATA[<p>@Stephan:<br />
How is that different from subclassing a Java class, then overwriting a method (say, equals), with a version that violates its contract?  Pretty hard to detect automatically, and it happens all the time in the wild.</p>
<p>I am far from defending monkey patching, but I&#8217;d rather have a language which is unsafe in places than one which is safe to the point that I can&#8217;t get anything done.</p>
<p>As for the particular problem instance, perhaps the Ruby runtime could warn when it overrides a method, and (unless permitted by some configuration option) bail out if it detects overriding of core functionality.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig</title>
		<link>http://kurt.karmalab.org/2008/04/24/monkey-patching-core-classes-bad/comment-page-1/#comment-236</link>
		<dc:creator>Craig</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">urn:uuid:{a.guid}#comment-236</guid>
		<description>@michaelw: Monkey patching is entirely different to subclassing. For a start, subclasses are part of the static type system, and therefore are known before compilation and are guaranteed not to change afterward. To change a method by subclassing, you must create a new type that inherits from the original, following the language&#039;s rules on inheritance (protected, private, etc) and that type exists in your own code. It only affects objects of that type that you specifically create, whereas monkey patching affects  EVERY instance of the base type.

In summary, inheritance is a controlled, static way of creating new types that behave similarly, but differently, to other types. Monkey patching is a way of hacking behaviour into classes, outside of any sort of type control system. It can create hard to find bugs like this one because you never know, at runtime, whether the method you are calling is quite the one you expect.</description>
		<content:encoded><![CDATA[<p>@michaelw: Monkey patching is entirely different to subclassing. For a start, subclasses are part of the static type system, and therefore are known before compilation and are guaranteed not to change afterward. To change a method by subclassing, you must create a new type that inherits from the original, following the language&#8217;s rules on inheritance (protected, private, etc) and that type exists in your own code. It only affects objects of that type that you specifically create, whereas monkey patching affects  EVERY instance of the base type.</p>
<p>In summary, inheritance is a controlled, static way of creating new types that behave similarly, but differently, to other types. Monkey patching is a way of hacking behaviour into classes, outside of any sort of type control system. It can create hard to find bugs like this one because you never know, at runtime, whether the method you are calling is quite the one you expect.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: she/farun@hotmail.com</title>
		<link>http://kurt.karmalab.org/2008/04/24/monkey-patching-core-classes-bad/comment-page-1/#comment-237</link>
		<dc:creator>she/farun@hotmail.com</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">urn:uuid:{a.guid}#comment-237</guid>
		<description>First, it is nice that you allow blog comments. I applaude everyone that allows the visitors to voice their opinion on something. Many blogs dont want that.

Second, I agree that the described behaviour CAN be bad. But it is like the swiss knife - you dont need everything, but if you need it, it is there. Same with Ruby.
The thing is, while I do extend core classes of Ruby happily, I am somewhat wary to see this being done in other projects - I think I am agreeing with you on that.

The documentation should point this out somehow, so that a user can be aware of this.


However, and this must be said, the term &quot;monkey patching&quot; is derogative and incorrect. I refuse to see such a name used for the described behaviour, and whenever I see proponents of this terms using it, I go and flame them. But of course not in your blog, since you allow comments. :)

I will happily flame them on mailing lists whenever they refer to changing behaviour of core objects as &quot;monkey patching&quot;.  (It has happened at least twice before on the Ruby mailing list by two different people.)</description>
		<content:encoded><![CDATA[<p>First, it is nice that you allow blog comments. I applaude everyone that allows the visitors to voice their opinion on something. Many blogs dont want that.</p>
<p>Second, I agree that the described behaviour CAN be bad. But it is like the swiss knife &#8211; you dont need everything, but if you need it, it is there. Same with Ruby.<br />
The thing is, while I do extend core classes of Ruby happily, I am somewhat wary to see this being done in other projects &#8211; I think I am agreeing with you on that.</p>
<p>The documentation should point this out somehow, so that a user can be aware of this.</p>
<p>However, and this must be said, the term &#8220;monkey patching&#8221; is derogative and incorrect. I refuse to see such a name used for the described behaviour, and whenever I see proponents of this terms using it, I go and flame them. But of course not in your blog, since you allow comments. <img src='http://kurt.karmalab.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I will happily flame them on mailing lists whenever they refer to changing behaviour of core objects as &#8220;monkey patching&#8221;.  (It has happened at least twice before on the Ruby mailing list by two different people.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Campbell</title>
		<link>http://kurt.karmalab.org/2008/04/24/monkey-patching-core-classes-bad/comment-page-1/#comment-238</link>
		<dc:creator>Michael Campbell</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">urn:uuid:{a.guid}#comment-238</guid>
		<description>I&#039;m still confused on this particular example; why is comparing a sorted array of nils to another sorted array of nils returning true, bad?  Did I misread?</description>
		<content:encoded><![CDATA[<p>I&#8217;m still confused on this particular example; why is comparing a sorted array of nils to another sorted array of nils returning true, bad?  Did I misread?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Avdi</title>
		<link>http://kurt.karmalab.org/2008/04/24/monkey-patching-core-classes-bad/comment-page-1/#comment-239</link>
		<dc:creator>Avdi</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">urn:uuid:{a.guid}#comment-239</guid>
		<description>Nice example of one of the more subtle monkey patching gotchas.</description>
		<content:encoded><![CDATA[<p>Nice example of one of the more subtle monkey patching gotchas.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert 'Groby' Blum</title>
		<link>http://kurt.karmalab.org/2008/04/24/monkey-patching-core-classes-bad/comment-page-1/#comment-240</link>
		<dc:creator>Robert 'Groby' Blum</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">urn:uuid:{a.guid}#comment-240</guid>
		<description>&lt;blockquote&gt;It can create hard to find bugs like this one because you never know, at runtime, whether the method you are calling is quite the one you expect.&lt;/blockquote&gt;

You mean, sort of like C++ with virtual overrides, slicing, operator overloads, implicit casts and constructors? :-&gt;

Corollary to this is that you need a executable spec for all classes you rely on - monkey patching is going to happen, whether it&#039;s useful or not. As far as I know, there are a couple of efforts underway to cover Ruby&#039;s base behavior with RSpec.</description>
		<content:encoded><![CDATA[<blockquote><p>It can create hard to find bugs like this one because you never know, at runtime, whether the method you are calling is quite the one you expect.</p></blockquote>
<p>You mean, sort of like C++ with virtual overrides, slicing, operator overloads, implicit casts and constructors? :-></p>
<p>Corollary to this is that you need a executable spec for all classes you rely on &#8211; monkey patching is going to happen, whether it&#8217;s useful or not. As far as I know, there are a couple of efforts underway to cover Ruby&#8217;s base behavior with RSpec.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kurt Schrader</title>
		<link>http://kurt.karmalab.org/2008/04/24/monkey-patching-core-classes-bad/comment-page-1/#comment-241</link>
		<dc:creator>Kurt Schrader</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">urn:uuid:{a.guid}#comment-241</guid>
		<description>Michael: The spec should have been testing that the arrays had two equal sorted group of values in them, but because the test setup was incorrect, the methods were returning arrays of nils.

Normally, [nil, nil] would throw an exception when you try to sort it, but it wasn&#039;t doing that any longe because of the patch.

I should have done a better job explaining that. :)</description>
		<content:encoded><![CDATA[<p>Michael: The spec should have been testing that the arrays had two equal sorted group of values in them, but because the test setup was incorrect, the methods were returning arrays of nils.</p>
<p>Normally, [nil, nil] would throw an exception when you try to sort it, but it wasn&#8217;t doing that any longe because of the patch.</p>
<p>I should have done a better job explaining that. <img src='http://kurt.karmalab.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan Leclercq</title>
		<link>http://kurt.karmalab.org/2008/04/24/monkey-patching-core-classes-bad/comment-page-1/#comment-242</link>
		<dc:creator>Stephan Leclercq</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">urn:uuid:{a.guid}#comment-242</guid>
		<description>@Michaelw : it is different because if I subclass String and replace a functionality, only modules that use my new String class (ie my own modules) will be affected by my changes. Otherwise, even the test framework itself may be affected and hit false positives or worse, false negatives.

&gt;&gt; bail out if it detects overriding of core functionality

What should be considered core functionality? You will not be able to find a suitable agreement for that. You will always find people complaining it to be either too restrictive or too loose (including me: -)</description>
		<content:encoded><![CDATA[<p>@Michaelw : it is different because if I subclass String and replace a functionality, only modules that use my new String class (ie my own modules) will be affected by my changes. Otherwise, even the test framework itself may be affected and hit false positives or worse, false negatives.</p>
<p>>> bail out if it detects overriding of core functionality</p>
<p>What should be considered core functionality? You will not be able to find a suitable agreement for that. You will always find people complaining it to be either too restrictive or too loose (including me: -)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
