To restate and generalize what others have said: Default values have one purpose: they define what is returned by a field's getter if the field is not set. The meaning applies equally to required and optional fields. That's it. The default value simply does not affect anything except for the getter method. In particular it is never sent over the wire.
On Thu, Sep 2, 2010 at 6:34 PM, Jeff Plaisance <[email protected]>wrote: > Maybe required with default specified could mean use the default if not > explicitly set. This change would also allow you to get rid of unused > required fields over 2 releases. If all software that compiles in your protocol is on a defined release schedule, then you can also take the approach of just changing the required field to optional, but continuing to always set it until the next release. In practice, we've found it very hard to coordinate release schedules in this way -- and too easy to *think* it's safe when it actually isn't -- so we instead just say that required fields shall remain required forever. > This might be too serious of an api change at this point, but it seems > like required has fallen out of favor anyway, so maybe this wouldn't be too > bad. Yes, behavioral changes that would affect existing .proto files are generally non-starters. > > > On Tue, Aug 24, 2010 at 4:47 PM, Kenton Varda <[email protected]> wrote: > >> On Wed, Aug 18, 2010 at 7:07 AM, Jeff Plaisance >> <[email protected]>wrote: >> >>> It seems like the issue here is that optional has been overloaded to mean >>> two different things: >>> >>> 1) Not really optional but in order to do rolling upgrades we're making >>> it optional. The default should be used if it is not set. In my opinion, >>> in this case there should be no "has" method because either its result is >>> irrelevant or it is being used to overload some other meaning on top of >>> optional. >>> 2) Optional in the sense of Option, Maybe, Nullable, empty, can be null, >>> whatever you want to call it. In my opinion this should be encapsulated in >>> the type so that the programmer is forced to handle all possible cases. The >>> has method should not be used for this because it is too easy to ignore. >>> >> >> Yes, I think you're right, and I see how it makes sense to distinguish >> these two by the presence or absence of an explicit default value. >> > > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
