Feature #5922

Migrate equal? to identical?

Added by Thomas Sawyer about 3 years ago. Updated over 2 years ago.

[ruby-core:42210]
Status:Rejected
Priority:Normal
Assignee:Yukihiro Matsumoto

Description

From Ruby docs: "the equal? method should never be overridden by subclasses: it is used to determine object identity (that is, a.equal?(b) iff a is the same object as b)."

I think it would make more sense to name such a method #identical?, since that is what it is doing --comparing identity. Over a sufficient period of time the current use of #equal? can be deprecated and possibly made better use of with a different definition. I realize this is not a minor change. This transition would probably be much like the one from #id to #object_id.

The reason I propose this, and why it is an issue for myself, is in of the design of assertion frameworks. For example, #assert_equal is a comparison of #==, not #equal?. We run into this naming conundrum and end up having to use assertion names that don't correspond well to the names of the underlying comparison. So that's the practical reason. But formally speaking, I think #identical? also better b/c it is more precise.

5922.pdf - Migrate equal? to identical? (73.3 KB) Thomas Sawyer, 07/01/2012 08:48 AM

History

#1 Updated by Peter Vandenabeele about 3 years ago

+1

One could also be even more descriptive: "same_object?"

#2 Updated by George Koehler about 3 years ago

=begin
The name of #equal? is part of a pattern.

In Common Lisp:
(eq a b) ; most strict
(eql a b)
(equal a b)
(equalp a b) ; least strict

In Ruby:
a == b # least strict
a.eql? b
a.equal? b # most strict

If #equal? loses its name, the pattern would be less obvious. Also, #eql? would lose its position between #== and #equal?.

If #equal? loses its name, I suggest that #eql? also loses its name.
* #equal? might become #identical? or #same_object?
* #eql? might become #hash_equal?

I guess that #eql? must not lose its name, because too much Ruby code already calls or defines #eql?.
=end

#3 Updated by Yusuke Endoh about 3 years ago

  • Status changed from Open to Assigned
  • Assignee set to Yukihiro Matsumoto

#4 Updated by Thomas Sawyer almost 3 years ago

#5 Updated by Yusuke Endoh almost 3 years ago

Received, thank you!

Yusuke Endoh mame@tsg.ne.jp

#6 Updated by Yutaka HARA over 2 years ago

Yusuke, do you know if this proposal is accepted as 2.0.0 feature at the Ruby developer meeting?

#7 Updated by Yusuke Endoh over 2 years ago

  • Status changed from Assigned to Rejected

Hello trans and yhara,

2012/10/25 yhara (Yutaka HARA) redmine@ruby-lang.org:

Yusuke, do you know if this proposal is accepted as 2.0.0 feature at the Ruby developer meeting?

Oops! I forget to write the result. Very sorry.

This feature request was rejected at the developers' meeting (7/21).

From a philosophical perspective, matz agreed that "identical?" was
more appropriate name.
But from a practical perspective, matz said we never delete "equal?",
and the name "identical?" has been already used, e.g., File#identical?.
So he rejected this proposal.

Yusuke Endoh mame@tsg.ne.jp

#8 Updated by Thomas Sawyer over 2 years ago

Someone else suggested #same? as alternate name.

Seems unfortunate to see a clear improvement held back by tradition alone.

Also available in: Atom PDF