News for hackers. Stuff that matters.
Re:Typical: Data interchange with algebraic data types by pickledish on Sunday May 21, 2023 @06:55PM (#36025379)
> Note: An optional field in a choice isn't simply a field with an option type/nullable type. The word "optional" here means that readers can ignore it and use a fallback instead, not that its payload might be missing

Hmm, this is new to me -- is this a Typical concept, or something more general around protobuf-enums that I just haven't run into before?

(oh, and besides my question, strong agreement with everyone else here, cool lib and great documentation!)

Re:Typical: Data interchange with algebraic data types by stepchowfun on Sunday May 21, 2023 @08:29PM (#36026025)
This is a Typical concept. I haven't seen this approach to optionality for sum types in any other serialization framework.

Programmers have good intuition for what it means for a field in a struct to be optional: it's either there or it's not. But for a sum type, what does it mean for a case to be "missing"? It's not quite as obvious, but it helps to think about what responsibilities are placed on writers vs. readers: optionality for a struct relaxes the burden on writers (they don't have to set the field), whereas for a sum type the burden is relaxed on readers (they don't have to handle the case).