Hacker News new | past | comments | ask | show | jobs | submit login

But it's not true. Mary is a sign-holder. She's holding a sign that says "32 Crestview Road". John is also a sign-holder. Today his sign also says "32 Crestview Road".

Question: is Mary John?

You want the answer to be "yes" (Mary is John) since the is operator asks whether they hold addresses which have the same value.

But of course it's a broken terminology, because Mary and John are two different people, with their own physical locations etc. So you're overloading a word "is". I get that it works, but so does anything else you make programmers learn.




I think Haskell gets it right. All values are immutable. Calling == for two values of some type invokes the Eq implementation for that type, e.g. for strings it's string equality. For the type "IORef a" (box that can contain different a's at different points in time) it compares the identity of the box, not the contents. In fact it can't compare contents, because the type of == stops it from using impure operations like accessing current contents.

The same approach could work in imperative or OO languages. For immutable types == should be value equality, while mutable types are analogous to IORef or IOArray, so == should be reference equality. It comes down to observational equality, different instances of the number 2 shouldn't be distinguishable, but different mutable containers with the same contents should be distinguishable because you can make their contents different. I think observational equality is a good fit for pretty much all uses of equality in programming.


But in the ideal situation it would be

    assertTrue(mary.getSign == john.getSign)
    assertFalse(mary.getSign is john.getSign)
    assertFalse(mary == john)
    assertFalse(mary is john)


right, you and I are agreed and your third sentence is exactly what I was arguing for - it goes against the OP's request that that third sentence evaluate to true.

this was the OP in this thread:

https://news.ycombinator.com/item?id=14348066




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: