[
https://issues.apache.org/jira/browse/THRIFT-428?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12695809#action_12695809
]
David Reiss commented on THRIFT-428:
------------------------------------
I'm on board with this, since the current level of support is not good, the
prospects are not great, and the value of these constructs is suspect. I doubt
it will affect many (any?) people. A few bits of anecdotal evidence:
- I grepped through Facebook's codebase and found about 200 occurrences of
"map" types in .thrift files. Every one was an integer, enum (effectively an
integer), string, or typedef of the same. There were no structures or
containers as keys. We have very few uses of the set type, but it had the same
result.
- Using structures or containers as map keys (or set elements) in PHP is
currently impossible. I've never heard someone from Facebook complain about
this. I think one person might have mentioned it on the dev list.
We could possibly preserve the current behavior with a compiler flag for people
who need access to saved data.
I'm not aware of any reason to forbid doubles as map keys, but it doesn't seem
to be a feature in much demand.
> Restrict map keys to integers and strings only
> ----------------------------------------------
>
> Key: THRIFT-428
> URL: https://issues.apache.org/jira/browse/THRIFT-428
> Project: Thrift
> Issue Type: Improvement
> Components: Compiler (General)
> Affects Versions: 0.1
> Reporter: Chad Walters
> Fix For: 0.1
>
>
> For the sake of better interoperability, particularly with PHP, it would be a
> good idea to restrict map keys to be only of integer and string type.
> Handling of structures and containers as key types is a pretty mixed bag
> across the main supported languages. The current state of affairs is:
> C++: Containers with containers as keys (with no structs involved) are fine.
> If a struct (or container of structs, or container of containers of structs,
> etc.) is to be used as a map key, it must have a comparison (less than)
> operator defined.
> Java: Containers and structs can be used as map keys or set elements. It is
> not entirely safe, but this is the Java convention (trust the application
> developer). structs cannot be used in sorted containers. Using structs as
> map keys without an optional dependency (apache commons lang) is very
> inefficient because structures all have a hashCode of 0 without it. (Can
> binaries be used as keys?)
> Python: Using mutable containers as map keys is impossible. Using mutable
> structures as map keys is possible, but unsafe and goes against a very strong
> Python convention. We are pretty close to having implementations of
> immutable containers and structures, but the code will probably end up being
> pretty bulky or pretty skeevy.
> Ruby: (Maybe someone can fill in more details?) Structures as map keys are
> very inefficient because all structures have a hash code of zero.
> PHP: Using structures or containers as map keys (or set elements) in PHP is
> currently impossible, and might be impossible to implement. Only strings and
> numbers can be associative array keys in PHP.
> Erlang: Any struct or container can be a map key or set element. There are
> no safety or performance issues. Erlang is pretty cool like that.
> I'd like us to consider doing this for 0.1 so it's in there for the first
> official Apache release.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.