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

Randy Abernethy commented on THRIFT-2473:
-----------------------------------------

Default requiredness is a pretty important Thrift feature. Defatult 
requiredness fields (like xx above) are always written, so they are not like 
optional, and they do not need to be present in the stream on the read side, so 
they are not like required. Default requiredness fields allow interfaces to 
evolve (you can delete or add default requiredness fields safely, particularly 
if you give them default values). 

The advantage of default requiredness over optional is that it allows the field 
to work like a normal field in the target language, with no need for optional 
overhead, setters, isset, etc. However, the C++ compiler has been outputting 
isset bools for default requiredness fields since at least 2010 per git blame. 

The isset provides the benefit of allowing the reader to know whether the field 
was serialized or not. Like Vitali, I think this dilutes the semantic and value 
of default requiredness a little. On the other hand some may use this flag to 
know if old clients using old IDL failed to pass the value. In cases where non 
trivial initialization of the default field is required this may be useful.

While I would rather we constrain isset for default requiredness to the read() 
deserialier like Vitali I would suggest that taking the struct level issets 
away could impact existing code. On the margin I think this makes it worth 
leaving in place. If someone else feels strongly the other way I would defer 
though.

> _isset entries shouldn't be generated for non-optional fields
> -------------------------------------------------------------
>
>                 Key: THRIFT-2473
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2473
>             Project: Thrift
>          Issue Type: Bug
>          Components: C++ - Compiler
>            Reporter: Vitali Lovich
>
> There's quite a bit of memory overhead (4 bytes per field) that's wasted on 
> every single type.  The __isset field is unused by the thrift type for fields 
> not annotated optional.
> Additionally, it causes confusion in program code since people never know 
> whether or not the __isset struct can be checked for a particular field or 
> not (e.g. for non-optional fields it would never get set normally unless you 
> deserialized it).



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to