Arc Forumnew | comments | leaders | submitlogin
3 points by fallintothis 4392 days ago | link | parent

Most programmers don't actually use eq that often. Python and ruby and perl still don't have it.

Most languages have only eq and no equal: the == operator in Ruby/Python compares by object reference.

The first statement is startlingly flimsy, and the second is outright false. Equality is rather involved in all three languages.

- Python has address and value comparison (http://docs.python.org/2/reference/expressions.html#is vs http://docs.python.org/2/reference/datamodel.html#object.__e...), but == dispatches to the __eq__ method, so is arbitrarily precise, in principle.

  >>> [1,2,3] is [1,2,3]
  False
  >>> [1,2,3] == [1,2,3]
  True
- Ruby is similarly user-definable, which gives inconsistent semantics; plus, there are two types of comparisons: http://ruby-doc.org/core-1.9.3/Object.html#method-i-eql-3F vs http://ruby-doc.org/core-1.9.3/Object.html#method-i-3D-3D-3D.

  irb(main):001:0> class A
  irb(main):002:1> end
  => nil
  irb(main):003:0> a = A.new
  => #<A:0x8f6dd3c>
  irb(main):004:0> a == a
  => true
  irb(main):005:0> a == a.clone
  => false
  irb(main):006:0> x = "abc"
  => "abc"
  irb(main):007:0> x == x
  => true
  irb(main):008:0> x == x.clone
  => true
  irb(main):009:0> (1..10) == 10
  => false
  irb(main):010:0> (1..10) === 10
  => true
- Perl (near as I can tell) doesn't have anything in the way of user-definable comparison, but still has separate operators. Granted, I don't think the separation is related to the reference-vs-value thing---I don't do Perl much, so the semantics confuse me:

  $ perl -le 'print "abc" == "ABC" ? "true" : "false"'
  true
  $ perl -le 'print "abc" eq "ABC" ? "true" : "false"'
  false
It'll be hard to appeal to the authority/popularity of most languages, because equality is a tricky concept with many meanings---whether or not it's specifically the address-vs-value (eq-vs-equal) thing.


1 point by akkartik 4392 days ago | link

Most interesting! I wasn't aware of the variants without the '=' in any of the languages.

-----