You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "James E. King III (JIRA)" <ji...@apache.org> on 2019/01/03 14:11:00 UTC

[jira] [Commented] (THRIFT-2772) reduce manual maintenance required for cpp_type & cpp_include

    [ https://issues.apache.org/jira/browse/THRIFT-2772?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16733079#comment-16733079 ] 

James E. King III commented on THRIFT-2772:
-------------------------------------------

This is an interesting way to define types.  In fact if you boil it all the way down, you could in theory have no pre-defined types and then include a standard set of thrift types that maps things like byte, i8, u32, string, and the like to platform-specific types.  That said, I'm not sure anyone's up for the task of doing it.  I like the notion that Thrift provides some core types you can build on, but I'm not as convinced the ability to define ones own container classes (thus making them potentially non-portable to other languages) is a good idea.

> reduce manual maintenance required for cpp_type & cpp_include
> -------------------------------------------------------------
>
>                 Key: THRIFT-2772
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2772
>             Project: Thrift
>          Issue Type: Improvement
>          Components: C++ - Compiler, Compiler (General)
>            Reporter: Vitali Lovich
>            Priority: Minor
>
> If I want to reference thrift types in a custom unordered_map currently:
> {code}
> // foo.thrift defines Foo
> namespace cpp me::thrift::foo
> // bar.thrift defined Bar
> namespace cpp me::thrift::bar
> // foobar.thrift
> namespace cpp me::thrift
> include "foo.thrift"
> include "bar.thrift"
> cpp_include "<unordered_map>"
> message Foobar {
>     map cpp_type "std::unordered_map<foo::Foo, bar::Bar>" <Foo, Bar> mapping;
> }
> {code}
> Downsides:
> * Requires me to have a good rule for generating package names from the get-go.
> * If I change the namespace name, I have to know *all* the spots to update it.
> * If I change the type name, I have to modify it in an extra spot that's not validated by the compiler.
> * I have to duplicate the cpp_include statement across all thrift files & know the mapping.
> A more maintainable mechanism would be a type-mapping file supported by the compiler.
> {code}
> type UnorderedMap<T1, T2> {
>     cpp_include = "<unordered_map>"
>     cpp_type = "std::unordered_map<$T1, $T2>"
>     java_type = "java.util.HashMap"
> }
> {code}
> Then:
> {code}
> include "UnorderedMap.thrift"
> message Foobar {
>     UnorderedMap<Foo, Bar> foo;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)