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

Ben Sigelman commented on THRIFT-2429:
--------------------------------------

As I mentioned earlier, required fields are problematic for long-lived systems. 
Certain fields may seem "logically required", but when large messages get 
refactored over the period of years, things get split apart, placed in 
substructures, etc, and required fields sometimes move or disappear despite the 
original author's best intentions. In the protobuf universe, for instance, it 
was a best practice (at Google) to use optional fields exclusively and do any 
validation in the software layer above raw protobuf parsing. I can go into more 
detail about motivations, etc, if that's desirable.

Anyway, briefly: optional is definitely not an optimization. It is the best 
practice for writing messages that will be evolution-friendly. E.g., read the 
admonitions under "required is forever" 
[here|http://diwakergupta.github.io/thrift-missing-guide/#_defining_structs].

And getting back to this actual proposal, whether a field has a default or not 
should have no bearing on what's serialized; it should only affect how 
thrift-compiled structs are initialized. That's well-defined, easy to explain, 
and will not implicitly bake all default values into the wire protocol.

> Provide option to not write default values, rely on receiver default 
> construction instead
> -----------------------------------------------------------------------------------------
>
>                 Key: THRIFT-2429
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2429
>             Project: Thrift
>          Issue Type: Improvement
>          Components: C++ - Compiler
>    Affects Versions: 0.9.1
>            Reporter: Chris Stylianou
>            Assignee: Randy Abernethy
>              Labels: default, optional, required
>
> Would there be any objections to a patch that does not write default values 
> (essentially the same logic as the optional attributes). This obviously 
> relies on the receiving application using the same IDL version to ensure the 
> defaults used on object construction match the senders.



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

Reply via email to