Thanks to visit codestin.com
Credit goes to programming.dev

  • bleistift2@sopuli.xyz
    Codestin Search App
    Codestin Search App
    English
    Codestin Search App
    10
    ·
    3 months 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.

    • calcopiritus@lemmy.world
      Codestin Search App
      Codestin Search App
      Codestin Search App
      5
      ·
      3 months 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.

    • expr
      Codestin Search App
      Codestin Search App
      Codestin Search App
      5
      ·
      3 months 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.

    • anton@lemmy.blahaj.zone
      Codestin Search App
      Codestin Search App
      Codestin Search App
      1
      ·
      3 months 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.