3 ms·
Is there really any good reason for code-gen? Just because “google did it” doesn’t mean it’s a good idea.
by jl2718 6y ago
Is there really any good reason for code-gen? Just because “google did it” doesn’t mean it’s a good idea.
- q3k 6y agoType safety for your serialization/RPC layer.
- jeffbee 6y agoProtobuf does not provide any type safety whatsoever. The name of the type of the message is carried in a side-channel, and the interpretation of that name is completely up to the endpoint that deserializes the message.
- q3k 6y agoOnce you dispatch your binary/text protobuf into a proto message type however, you do get type safety, and it makes sense to carry over that type safety to implementing languages. Plus, Any [1] is an effort to standardize the ability to carry the proto type (as a global identifier that can be used to retrieve its schema) alongside its serialized format. [1] - https://developers.google.com/protocol-buffers/docs/proto3#any https://developers.google.com/protocol-buffers/docs/proto3#a...
- jakeva 6y agoHow about because for deterministic output, it suits the problem? Just because you can do it by hand doesn't mean I want to.
- foolfoolz 6y agocode generation is great for sharing data models and writing clients for services without dependencies
- SOLAR_FIELDS 6y agoExactly this. Imagine you work at BigCorp and use protobuf to pass data around - now you have a unified data model you can share and everyone can use the same client to access it without going through the trouble of maintaining all those getters and setters. Rolling your own getters and setters is fine in a small project but you really see the advantages of the code gen approach once you are dealing with multiple different teams in an org working with the same complex data model. There are definitely some downsides to the approach though, mostly typical problems you would expect with machine generated code. Namely that it’s verbose and if you have a super complex protobuf data model (hundreds or thousands of fields) and want to ship a fatjar or similar bundling of dependencies you can run into some size issues.
- devit 6y agoIt's required to have static type checking, which is essential. Also, way more time/memory efficient.