3 ms·
These objections are interesting. I have mixed opinions on protos, I think overall I'm mostly in favor. I'm a bit confused by this set of objections though. Wh
by joshuamorton 8y ago
These objections are interesting. I have mixed opinions on protos, I think overall I'm mostly in favor. I'm a bit confused by this set of objections though.
While oneof fields cannot be repeated, oneof fields can be arbitrary protos, so they can contain repeated fields. In other words, you can have a (pseudo-proto)
oneof {
RFoo {
repeated Foo;
}
RBar {
repeated Bar;
}
}
so in practice this isn't a restriction. If anything, its a (very minor) api wart.
As for maps, I'd say don't use them. I have, I don't think they're very useful, except for prototyping things. `repeated (string key, string value)` is just as useful for prototyping things, and you should be quick to promote things to fields. Optional fields aren't costly.
I'm also in the minority who thinks that the `has_foo` methods are a smell, and everything should always be set to a default value[0]. If it really matters, one can define a maybe type via a oneof, but that should be the exception, not the norm. Most people disagree with that though, so maybe I'm crazy and you should ignore me.
[0]: But if that's not the case, everything should be optional, nothing required.
- xyzzyz 8y agoWhile oneof fields cannot be repeated, oneof fields can be arbitrary protos, so they can contain repeated fields. In other words, you can have a oneof, so in practice this isn't a restriction. If anything, its a(very minor) api wart. That's right. Moreover, oneof repeated and repated oneof are two different types: in first, you have a list of X, or a list of Y, or a list of Z etc, and in the second, you have a list such that any element can be either X, Y or Z. Both can be cleanly expressed with existing API, so I see no reason to do any special treatment.
- aaaaaaaaaab 8y agorepeated(oneof(Foo, Bar)) is not the same as oneof(repeated(Foo), repeated(Bar))
- joshuamorton 8y agoCorrect, both of those are possible to represent as is though. Each oneof just requires and extra proto to wrap it. So you have repeated OneaofWrapper { oneof { Foo Bar } } Or what I did in my previous comment.