since most other languages default to reference equality for reference types
It is a surprising behaviour, regardless of how many languages do it. Any empty array is semantically the same thing as any other empty array.
Having == perform a pointer comparison only really makes sense when the types you're dealing with are raw pointers (since there is no better notion of equality for raw pointers). For other types, it is a confusing and unexpected behaviour - if you write ==, you almost certainly want to check for semantic equality.
I guess it depends on how your intuition is calibrated. My first language was Java, which doesn't allow operator overloading, so == can only be reference equality.
View all comments
Show parent comment
3
u/TDplay Jul 17 '24
It is a surprising behaviour, regardless of how many languages do it. Any empty array is semantically the same thing as any other empty array.
Having
==perform a pointer comparison only really makes sense when the types you're dealing with are raw pointers (since there is no better notion of equality for raw pointers). For other types, it is a confusing and unexpected behaviour - if you write==, you almost certainly want to check for semantic equality.