3 ms·
> It's perfectly okay to use object identity when comparing immutable data structures, but it's usually a bug if the data structure is mutable. I don't underst
by jdmichal 11y ago
> It's perfectly okay to use object identity when comparing immutable data structures, but it's usually a bug if the data structure is mutable.
I don't understand this statement. The only thing immutability provides here is the ability to know that an object didn't change by knowing that it's the same object. There's no guarantee of value equality from identity unless all objects are interned.
- chadaustin 11y agoAh, yeah, perhaps I should have elaborated more. It's a subtle issue, but it's one that comes up all the time when optimizing React by removing unnecessary renders. With immutable data structures, you know that x == y implies, even if x was initialized a while ago, that the data is the same. With mutable data, that's not true -- perhaps the values referenced by x have changed value in the meantime, so x == y does not imply that the data is the same.