Re: [RFC][VOTE] Objects as Keys
| From: | Levi Morrison | Date: | Thu, 18 Dec 2014 00:05:20 +0000 |
| Subject: | Re: [RFC][VOTE] Objects as Keys | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-79798@lists.php.net to get a copy of this message | ||
>> Programmable hashes of objects should be external to the object anyway
>> because eventually someone wants to store the same object in a
>> different way in two different structures.
>
> That is the requirement that no language I can think of implements -
> Java, Python, Ruby, C# all have programmatic hash method, and none of
> them changes it for different structures.
C++ commonly does this. You pass a "hash function" as a template or
constructor argument and use that for the structure. Additionally,
this allows you to easily support types that don't natively provide
internal hashing functions (such as objects from a third party
library).
In this case, doing it like Java, C# et al is an example of most
languages getting it wrong, not them getting it right.