4 ms·
The author lost me at “make all fields required” for some nice type system properties. required was a mistake, in my opinion and in the proto 3 spec’s opinion.
by mattnewton 7y ago
The author lost me at “make all fields required” for some nice type system properties.
required was a mistake, in my opinion and in the proto 3 spec’s opinion. Capn’ proto has a nice write up here too With essentially the same points I would make but written better:
https://capnproto.org/faq.html#how-do-i-make-a-field-required-like-in-protocol-buffers https://capnproto.org/faq.html#how-do-i-make-a-field-require...
I think protos might just be being used for the wrong thing in the author’s example. You shouldn’t replace your application’s data structures with protos everywhere, in my experience protobufs are for when you want to serialize and you write a bunch of backwards compatible serialization code by hand. This code is hard to generate because it encapsulates all the changing requirements needed to work across different versions, so the lack of general type system tools doesn’t really offer opportunity to cut down on the schlep. If you don’t have these problems, don’t think you will have these problems, evaluate whether the tech is right for you. I’ve worked on projects before at Google that have made this mistake and threw away the nice data model expressable in a language to use proto interfaces where there was no need for serialization. I don’t think the solution is to have protos expanded to be comparable to that in every language.
Disclaimer: Googler who is forced to use a lot of protos, my opinions are my own and and I didn’t design or ever work on them directly. Probably also just an amateur :D
- davedx 7y ago> I think protos might just be being used for the wrong thing in the author’s example. You shouldn’t replace your application’s data structures with protos everywhere Yeah, I really scratched my head at that part. Even in my small line-of-business TypeScript apps, I often have separate interfaces for the "API models" (what I get as JSON from the API) and the "app models" (the models my app uses to represent the internal state of things). In the big .NET platform I work on, we have multiple namespaces of Models and Dto's to represent different things at different interface boundaries. Why on earth would you try to re-use a network-layer interface in levels several layers higher? That's crazy talk!
- kentonv 7y ago> Why on earth would you try to re-use a network-layer interface in levels several layers higher? That's crazy talk! It's theoretically ugly but in practice it can be really convenient. Translating large structures between different formats is tedious and error-prone... sometimes it's just a lot faster and easier to leave it as a Protobuf.
- seriesf 7y agoYes but proto 3 was also a mistake. Throwing away presence entirely was wrong and not preserving unknowns was also wrong. Proto 2 forever, imho.
- xyzzyz 7y agoI agree. Preserving unknowns fortunately was recognized as mistake, and fixed in some more recent version, and presence can be worked around: it is still preserved for message types, so you only need to wrap your primitives into objects[1], Java style. [1] - https://developers.google.com/protocol-buffers/docs/reference/google.protobuf https://developers.google.com/protocol-buffers/docs/referenc...
- lonelappde 7y agoThat's not "agree" with "not preserving unknowns was also wrong."
- xyzzyz 7y agoSorry, I meant not preserving unknowns was also wrong. Proto2 did preserve them, then proto3 didn’t, and then they realized it was a bad idea and went back to preserving them.
- rcfox 7y agoIt can be approximated with a single-item `oneof` field. It's ugly and boilerplatey, but at least it's binary-compatible with proto2 and gives the original behaviour. My main problem with proto2 these days is that I needed to interface with some C# code, and there is no proto2 library for C#!
- kentonv 7y ago> there is no proto2 library for C#! Looks like that's getting fixed! https://github.com/protocolbuffers/protobuf/blob/master/docs/csharp/proto2.md https://github.com/protocolbuffers/protobuf/blob/master/docs... https://github.com/protocolbuffers/protobuf/pulls?q=is%3Apr+author%3AObsidianMinor https://github.com/protocolbuffers/protobuf/pulls?q=is%3Apr+...
- joatmon-snoo 7y agoWorth calling out that Google literally compiled a list of outages caused by `required` fields before killing that field parameter.