• Kairos@lemmy.today
      link
      fedilink
      arrow-up
      8
      arrow-down
      2
      ·
      5 days ago

      This syntax isn’t actually a problem by itself. Go does this too (no operator overloading)

      • Gremour@lemmy.world
        link
        fedilink
        arrow-up
        3
        arrow-down
        1
        ·
        edit-2
        5 days ago

        In Go you can compare structure instances with == (by value). You can also compare pointers (in which case they can be different even if values are equal). You get what you ask for.

        Also, I’ve never needed “Equals” method in Go.

  • bleistift2@sopuli.xyz
    link
    fedilink
    English
    arrow-up
    10
    ·
    5 days ago

    Is there ever an instance when you do want to compare object identity instead of “equal”-ness? I find this behaviour just confusing for beginners and not useful for experts.

    • anton@lemmy.blahaj.zone
      link
      fedilink
      arrow-up
      1
      ·
      3 days ago

      Is there ever an instance when you do want to compare object identity instead of “equal”-ness?

      Maybe if you have to check if the object is one you already hold a lock for or account for some similar consequence of questionable architecture.

    • Redkey@programming.dev
      link
      fedilink
      arrow-up
      3
      ·
      4 days ago

      Not to take away from your very good point, but I think the word you might be looking for is “eqivalence”.

    • expr@programming.dev
      link
      fedilink
      arrow-up
      5
      ·
      5 days ago

      99.99% of the time you want to compare by value, which is why languages defaulting to comparing by reference is a stupid default.

    • calcopiritus@lemmy.world
      link
      fedilink
      arrow-up
      5
      ·
      5 days ago

      There are use cases. Like containers where the pointer to the object itself is the key (for example a set). But they are niche and should be implemented by the standard library anyway. One of the things I hate most about Java is .equals() on strings. 99.999% of times you compare strings, you want to compare the contents, yet there is a reserved operator to do the wrong comparison.

      • marcos@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        5 days ago

        Java has the hash interface for using in containers. You don’t need to override equality for it.