Why .NET, Ruby and Java compare structures by its hash code?
How about recursive structure comparison?
Anyone know this?
Why .NET, Ruby and Java compare structures by its hash code?
How about recursive structure comparison?
Anyone know this?
Just GET it OFF out my mind!!
You can implement hash tables in pretty much any programming language, so there is nothing special about Ruby and Java in that regard. Hash tables can come in handy when you want constant time insertion, deletion and search of elements, but do not care about the order of elements.Originally Posted by audinue
Comparing objects by comparing their components is useful too. It is all a matter of what are your requirements.Originally Posted by audinue
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Is it slower than comparing object hash codes so they aren't using it instead?Originally Posted by laserlight
Just GET it OFF out my mind!!
What are you talking about? I don't know about Ruby, but neither .Net nor Java "compare structures by its hash code". For one, Java doesn't even have structures. For another, the default equals()/Equals() compares references, so unless you override the method with your specific method of comparison (which depends heavily on context, but will probably be element-wise recursive comparison for value types), object identity is what you get.
Same for hash code computation. The default hashCode()/whatever it's called in .Net uses the reference value with perhaps a simple bit shuffling for better distribution, so hashing happens based on object identity.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
A class is a structure called schema and it can contains data.What are you talking about? I don't know about Ruby, but neither .Net nor Java "compare structures by its hash code". For one, Java doesn't even have structures.
Just GET it OFF out my mind!!
Who are "they"?Originally Posted by audinue
That does not really make sense to me, but then I do not know Ruby either. I took your use of "structure" to mean any kind of data structure, and in that sense I regard CornedBee's objection as being too pedantic concerning jargon.Originally Posted by audinue
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
True, that was unnecessarily pedantic. But then, C# does make a big difference between structures and classes (value types and ref types in CLR jargon), and Java doesn't have structures in the C# sense.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law