Hacker News new | ask | show | jobs
by joe_fishfish 1061 days ago
You absolutely can. You can also use Square’s excellent Wire library.
1 comments

You can but you’re going to have ? EVERYWHERE, which does drive the search for a native implementation that doesn’t make you deal with null everywhere
Is there another way you're supposed to represent optionals in Kotlin?
No, but it makes the code a mess because you’re handling optionals for every protobuf field deref. So you’ve got error handling all over the place. It looks like go’s error handling.
They really are optional though. This is inherent in the problem if you want to support arbitrary past and future versions. You need to decide what to do when the data is missing. Open file formats are a difficult problem. [1]

I might define a different class for a validated object, so version skew only needs to be dealt with at the system edge.

Maybe you don’t actually have that problem because you can make a closed-world assumption? For example, you control all writers and aren’t saving any old-format data, like in a database that has a schema. In that case you can make fields required.

[1] https://acko.net/blog/on-variance-and-extensibility/