<?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: Navigating the equality maze</title>
	<atom:link href="http://www.paulbutcher.com/2007/10/navigating-the-equality-maze/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.paulbutcher.com/2007/10/navigating-the-equality-maze/</link>
	<description></description>
	<lastBuildDate>Wed, 12 May 2010 14:44:07 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Sam Halliday</title>
		<link>http://www.paulbutcher.com/2007/10/navigating-the-equality-maze/comment-page-1/#comment-31</link>
		<dc:creator>Sam Halliday</dc:creator>
		<pubDate>Sat, 20 Oct 2007 00:08:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.texperts.com/2007/10/16/navigating-the-equality-maze/#comment-31</guid>
		<description>Aah... so the eqls is much more like the equals I&#039;m used to in Java. This code is certainly very terse... you&#039;re making me jealous :-) (mumbles something about having to deal with null...)</description>
		<content:encoded><![CDATA[<p>Aah&#8230; so the eqls is much more like the equals I&#8217;m used to in Java. This code is certainly very terse&#8230; you&#8217;re making me jealous <img src='http://www.paulbutcher.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  (mumbles something about having to deal with null&#8230;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Butcher</title>
		<link>http://www.paulbutcher.com/2007/10/navigating-the-equality-maze/comment-page-1/#comment-41</link>
		<dc:creator>Paul Butcher</dc:creator>
		<pubDate>Wed, 17 Oct 2007 22:59:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.texperts.com/2007/10/16/navigating-the-equality-maze/#comment-41</guid>
		<description>Sorry for the delayed comment, Sam - been in London all day.

Yes, the alternative semantics you&#039;re talking about are also entirely possible - this basically means making == behave exactly like eql? (i.e. return true if and only if the objects represent the same value) rather than trying to be &quot;clever&quot;. The following (only showing the definition of the == methods) is what you&#039;re after, I believe:

&lt;pre lang=&quot;Ruby&quot;&gt;
class Point
  def ==(other)
    self.class == other.class &amp;&amp; @x == other.x &amp;&amp; @y == other.y
  end
end

class ColouredPoint &lt; Point
  def ==(other)
    super &amp;&amp; @c == other.c
  end
end
&lt;/pre&gt;

With the same definitions as above, this gives:

&lt;pre lang=&quot;Ruby&quot;&gt;
p == q =&gt; true
p == r =&gt; false
s == t =&gt; false
s == u =&gt; true
p == s =&gt; false
s == p =&gt; false
r == s =&gt; false
s == r =&gt; false
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Sorry for the delayed comment, Sam &#8211; been in London all day.</p>
<p>Yes, the alternative semantics you&#8217;re talking about are also entirely possible &#8211; this basically means making == behave exactly like eql? (i.e. return true if and only if the objects represent the same value) rather than trying to be &#8220;clever&#8221;. The following (only showing the definition of the == methods) is what you&#8217;re after, I believe:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Point
  <span style="color:#9966CC; font-weight:bold;">def</span> ==<span style="color:#006600; font-weight:bold;">&#40;</span>other<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9966CC; font-weight:bold;">class</span> == other.<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#0066ff; font-weight:bold;">@x</span> == other.<span style="color:#9900CC;">x</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#0066ff; font-weight:bold;">@y</span> == other.<span style="color:#9900CC;">y</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> ColouredPoint <span style="color:#006600; font-weight:bold;">&lt;</span> Point
  <span style="color:#9966CC; font-weight:bold;">def</span> ==<span style="color:#006600; font-weight:bold;">&#40;</span>other<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">super</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#0066ff; font-weight:bold;">@c</span> == other.<span style="color:#9900CC;">c</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>With the same definitions as above, this gives:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">p</span> == q <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#CC0066; font-weight:bold;">p</span> == r <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
s == t <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
s == u <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#CC0066; font-weight:bold;">p</span> == s <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
s == <span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
r == s <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
s == r <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Halliday</title>
		<link>http://www.paulbutcher.com/2007/10/navigating-the-equality-maze/comment-page-1/#comment-40</link>
		<dc:creator>Sam Halliday</dc:creator>
		<pubDate>Wed, 17 Oct 2007 10:49:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.texperts.com/2007/10/16/navigating-the-equality-maze/#comment-40</guid>
		<description>also

&quot;to not allow equals to return false if the classes don’t match&quot;

should have been

&quot;to not allow equals to return true if the classes don’t match&quot;

I picked a bad day to give up coffee.</description>
		<content:encoded><![CDATA[<p>also</p>
<p>&#8220;to not allow equals to return false if the classes don’t match&#8221;</p>
<p>should have been</p>
<p>&#8220;to not allow equals to return true if the classes don’t match&#8221;</p>
<p>I picked a bad day to give up coffee.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Halliday</title>
		<link>http://www.paulbutcher.com/2007/10/navigating-the-equality-maze/comment-page-1/#comment-39</link>
		<dc:creator>Sam Halliday</dc:creator>
		<pubDate>Wed, 17 Oct 2007 10:45:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.texperts.com/2007/10/16/navigating-the-equality-maze/#comment-39</guid>
		<description>Sorry, this

&quot;Consider your objects p, s and u. s == p is true, p == t is true, but s == t is false.&quot;

should read

&quot;Consider your objects p, s and t. s == p is true, p == t is true, but s == t is false.&quot;</description>
		<content:encoded><![CDATA[<p>Sorry, this</p>
<p>&#8220;Consider your objects p, s and u. s == p is true, p == t is true, but s == t is false.&#8221;</p>
<p>should read</p>
<p>&#8220;Consider your objects p, s and t. s == p is true, p == t is true, but s == t is false.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Halliday</title>
		<link>http://www.paulbutcher.com/2007/10/navigating-the-equality-maze/comment-page-1/#comment-38</link>
		<dc:creator>Sam Halliday</dc:creator>
		<pubDate>Wed, 17 Oct 2007 10:44:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.texperts.com/2007/10/16/navigating-the-equality-maze/#comment-38</guid>
		<description>Hmm, that solves symmetry... but only by breaking transitivity. i.e. if x == y is true and y == z  is true, implies x == z is true.

Consider your objects p, s and u. s == p is true, p == t is true, but s == t is false.

A widely adopted solution in Java is to not allow equals to return false if the classes don&#039;t match. I don&#039;t think that would be the expected behaviour in Ruby... so does this mean the transitivity rule is not assumed to hold in general?</description>
		<content:encoded><![CDATA[<p>Hmm, that solves symmetry&#8230; but only by breaking transitivity. i.e. if x == y is true and y == z  is true, implies x == z is true.</p>
<p>Consider your objects p, s and u. s == p is true, p == t is true, but s == t is false.</p>
<p>A widely adopted solution in Java is to not allow equals to return false if the classes don&#8217;t match. I don&#8217;t think that would be the expected behaviour in Ruby&#8230; so does this mean the transitivity rule is not assumed to hold in general?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Butcher</title>
		<link>http://www.paulbutcher.com/2007/10/navigating-the-equality-maze/comment-page-1/#comment-37</link>
		<dc:creator>Paul Butcher</dc:creator>
		<pubDate>Tue, 16 Oct 2007 23:49:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.texperts.com/2007/10/16/navigating-the-equality-maze/#comment-37</guid>
		<description>Sam, I believe that the following addresses the problem that you&#039;re concerned about:

&lt;pre lang=&quot;Ruby&quot;&gt;
class Point
  attr_reader :x, :y

  def initialize(x, y)
    @x, @y = x, y
  end

  def ==(other)
    @x == other.x &amp;&amp; @y == other.y
  end
end

class ColouredPoint &lt; Point
  attr_reader :c

  def initialize(x, y, c)
    super(x, y)
    @c = c
  end

  def ==(other)
    super &amp;&amp; (!other.respond_to?(:c) &#124;&#124; @c == other.c)
  end
end
&lt;/pre&gt;

This gives:

&lt;pre lang=&quot;Ruby&quot;&gt;
p = Point.new(1, 2)
q = Point.new(1, 2)
r = Point.new(3, 4)

p == q
=&gt; true
p == r
=&gt; false

s = ColouredPoint.new(1, 2, :red)
t = ColouredPoint.new(1, 2, :green)
u = ColouredPoint.new(1, 2, :red)

s == t
=&gt; false
s == u
=&gt; true

p == s
=&gt; true
s == p
=&gt; true
r == s
=&gt; false
s == r
=&gt; false
&lt;/pre&gt;

Which is what you&#039;re after, yes?</description>
		<content:encoded><![CDATA[<p>Sam, I believe that the following addresses the problem that you&#8217;re concerned about:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Point
  attr_reader <span style="color:#ff3333; font-weight:bold;">:x</span>, <span style="color:#ff3333; font-weight:bold;">:y</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>x, y<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@x</span>, <span style="color:#0066ff; font-weight:bold;">@y</span> = x, y
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> ==<span style="color:#006600; font-weight:bold;">&#40;</span>other<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@x</span> == other.<span style="color:#9900CC;">x</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#0066ff; font-weight:bold;">@y</span> == other.<span style="color:#9900CC;">y</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> ColouredPoint <span style="color:#006600; font-weight:bold;">&lt;</span> Point
  attr_reader <span style="color:#ff3333; font-weight:bold;">:c</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>x, y, c<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">super</span><span style="color:#006600; font-weight:bold;">&#40;</span>x, y<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@c</span> = c
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> ==<span style="color:#006600; font-weight:bold;">&#40;</span>other<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">super</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!other.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:c</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#0066ff; font-weight:bold;">@c</span> == other.<span style="color:#9900CC;">c</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This gives:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">p</span> = Point.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>
q = Point.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>
r = Point.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">3</span>, <span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">p</span> == q
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#CC0066; font-weight:bold;">p</span> == r
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
&nbsp;
s = ColouredPoint.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#ff3333; font-weight:bold;">:red</span><span style="color:#006600; font-weight:bold;">&#41;</span>
t = ColouredPoint.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#ff3333; font-weight:bold;">:green</span><span style="color:#006600; font-weight:bold;">&#41;</span>
u = ColouredPoint.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#ff3333; font-weight:bold;">:red</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
s == t
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
s == u
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">p</span> == s
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
s == <span style="color:#CC0066; font-weight:bold;">p</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
r == s
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
s == r
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span></pre></div></div>

<p>Which is what you&#8217;re after, yes?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Halliday</title>
		<link>http://www.paulbutcher.com/2007/10/navigating-the-equality-maze/comment-page-1/#comment-36</link>
		<dc:creator>Sam Halliday</dc:creator>
		<pubDate>Tue, 16 Oct 2007 20:02:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.texperts.com/2007/10/16/navigating-the-equality-maze/#comment-36</guid>
		<description>I still can&#039;t get my head around the need for the eql method... to me the 1.0 overwriting the 1 would be what I&#039;d expect. But I&#039;m not used to all these ducks :-)

How does Ruby deal with the subclassing symmetry equality problem? e.g. how does one override == for an object named Point which depends on parameters (x, y)? If a subclass ColouredPoint adds an additional RGB value and edits its equality appropriately... how is a == b implies b == a upheld?</description>
		<content:encoded><![CDATA[<p>I still can&#8217;t get my head around the need for the eql method&#8230; to me the 1.0 overwriting the 1 would be what I&#8217;d expect. But I&#8217;m not used to all these ducks <img src='http://www.paulbutcher.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>How does Ruby deal with the subclassing symmetry equality problem? e.g. how does one override == for an object named Point which depends on parameters (x, y)? If a subclass ColouredPoint adds an additional RGB value and edits its equality appropriately&#8230; how is a == b implies b == a upheld?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gavin Kistner</title>
		<link>http://www.paulbutcher.com/2007/10/navigating-the-equality-maze/comment-page-1/#comment-35</link>
		<dc:creator>Gavin Kistner</dc:creator>
		<pubDate>Tue, 16 Oct 2007 19:05:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.texperts.com/2007/10/16/navigating-the-equality-maze/#comment-35</guid>
		<description>An excellent, clear article. Thank you very much for taking the time to write this up.</description>
		<content:encoded><![CDATA[<p>An excellent, clear article. Thank you very much for taking the time to write this up.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: p-daddy</title>
		<link>http://www.paulbutcher.com/2007/10/navigating-the-equality-maze/comment-page-1/#comment-34</link>
		<dc:creator>p-daddy</dc:creator>
		<pubDate>Tue, 16 Oct 2007 10:54:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.texperts.com/2007/10/16/navigating-the-equality-maze/#comment-34</guid>
		<description>Just wanted to say that I saw this link on the ruby mailing list.

It&#039;s a remarkably clear explanation.

I wonder if you can somehow get the relevant pieces of your article incorporated into the core ruby documentation.

thanks!</description>
		<content:encoded><![CDATA[<p>Just wanted to say that I saw this link on the ruby mailing list.</p>
<p>It&#8217;s a remarkably clear explanation.</p>
<p>I wonder if you can somehow get the relevant pieces of your article incorporated into the core ruby documentation.</p>
<p>thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Butcher</title>
		<link>http://www.paulbutcher.com/2007/10/navigating-the-equality-maze/comment-page-1/#comment-33</link>
		<dc:creator>Paul Butcher</dc:creator>
		<pubDate>Tue, 16 Oct 2007 10:49:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.texperts.com/2007/10/16/navigating-the-equality-maze/#comment-33</guid>
		<description>Whups! Thanks Ron. Fixed now :-)</description>
		<content:encoded><![CDATA[<p>Whups! Thanks Ron. Fixed now <img src='http://www.paulbutcher.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
