You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Ben Taitelbaum (JIRA)" <ji...@apache.org> on 2009/11/13 05:01:39 UTC
[jira] Created: (THRIFT-627) should c++ have setters for optional
fields?
should c++ have setters for optional fields?
--------------------------------------------
Key: THRIFT-627
URL: https://issues.apache.org/jira/browse/THRIFT-627
Project: Thrift
Issue Type: Improvement
Components: Compiler (C++)
Environment: c++
Reporter: Ben Taitelbaum
It seems non-intuitive to me to have to set __isset.someField = true after setting an optional field someField on a struct. Would it make sense to have a set_someField method that would both set the field and modify __isset?
One of the cases for this is for when a field goes from being required to being optional, and it's easy to forget to set __isset in the code.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (THRIFT-627) should c++ have setters for optional
fields?
Posted by "David Reiss (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-627?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12777374#action_12777374 ]
David Reiss commented on THRIFT-627:
------------------------------------
I see no downside to generating these methods.
> should c++ have setters for optional fields?
> --------------------------------------------
>
> Key: THRIFT-627
> URL: https://issues.apache.org/jira/browse/THRIFT-627
> Project: Thrift
> Issue Type: Improvement
> Components: Compiler (C++)
> Environment: c++
> Reporter: Ben Taitelbaum
>
> It seems non-intuitive to me to have to set __isset.someField = true after setting an optional field someField on a struct. Would it make sense to have a set_someField method that would both set the field and modify __isset?
> One of the cases for this is for when a field goes from being required to being optional, and it's easy to forget to set __isset in the code.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (THRIFT-627) should c++ have setters for optional
fields?
Posted by "Rush Manbert (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-627?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12777554#action_12777554 ]
Rush Manbert commented on THRIFT-627:
-------------------------------------
Would you generate some equivalent for fields that are STL objects? In that case you can't write set_MyMap (value), but you could provide something like wrote_MyMap(void) that would take care of the __isset.
In general, setters would be useful, but they only solve the __isset problem halfway.
I have recently written some classes that I use to write wrappers for Thrift-generated C++ classes. The main point is to handle the __isset setting, especially in the case where I write a data member in a class that is contained within a parent class. If you write a data member of the contained class you need to write its __isset member, but you also need to write the __isset member in the parent class of the contained class. (parent in the ownership-sense, not inheritance) This needs to propagate up the ownership chain.
For STL objects, all I offer is a wasWritten(void) method that handles the __isset chain.
I believe that I could write a script that would read through my Thrift configuration files and auto-generate the wrappers, but it would be a lot better if the compiler would optionally do it for me. I know this is a lot more ambitious than adding setters to the currently generated classes, but it really helped me get out of __isset hell with the latest service that I wrote. While I'm sure that they can be improved, I would be happy to contribute the wrapper base classes. Is there any interest, or should I just shut up and keep this to myself? :-)
> should c++ have setters for optional fields?
> --------------------------------------------
>
> Key: THRIFT-627
> URL: https://issues.apache.org/jira/browse/THRIFT-627
> Project: Thrift
> Issue Type: Improvement
> Components: Compiler (C++)
> Environment: c++
> Reporter: Ben Taitelbaum
>
> It seems non-intuitive to me to have to set __isset.someField = true after setting an optional field someField on a struct. Would it make sense to have a set_someField method that would both set the field and modify __isset?
> One of the cases for this is for when a field goes from being required to being optional, and it's easy to forget to set __isset in the code.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.