3 ms·
Signal boosting this. I am the last person to be swayed by “use our magical design that solves all problems,” but in the case of protobufs, it solves most of th
by sillysaurusx 6y ago
Signal boosting this. I am the last person to be swayed by “use our magical design that solves all problems,” but in the case of protobufs, it solves most of them.
I didn’t like it until I was forced to use it. Now I’m not sure I’ll ever go back.
There’s a handy code snippet to turn any protobuf message into JSON:
from google.protobuf.json_format import MessageToJson
import json
from pprint import pprint as pp
pp(json.loads(MessageToJson(msg)))
Examples of turning arbitrary tensorflow objects into JSON: https://twitter.com/theshawwn/status/1331625739993575427?s=21 https://twitter.com/theshawwn/status/1331625739993575427?s=2...
- intricatedetail 6y agoWhy they use Java like code in Python? "MessageToJson" doesn't look idiomatic.
- singron 6y agoCapWords function names matches the C++ style guide at Google, not java. A lot of python uses autogenerated bindings to C++ code and reuses the same naming conventions. Even pure python code would use that style although their public styleguide doesn't mention it anymore.
- ipsum2 6y agoThe official protobuf library for Python is not pythonic at all.
- q3k 6y agoThis is because this follows Google’s internal Python styeguide, which was established well before PEP8 and even Python 2.x.
- joshuamorton 6y agoNotably this is no longer true[0]. While legacy stuff can still use the CapWords styling, snake_case names are preferred for all new methods and functions (including code that wraps c++). But this is a relatively recent change to the style guide, and the proto libraries far predate it. (As a response to a sibling of the parent, the same rules apply to internal code, CapWords should only be used for consistency within a file. All new code should be embrace it's snakey heritage). [0]: https://google.github.io/styleguide/pyguide.html#3162-naming-conventions https://google.github.io/styleguide/pyguide.html#3162-naming...