> But it's also describing some less obvious invariants, e.g. that a User will not have a phone number.
That's not right. For one, the `User` type might be extensible (what language is this?). For another one can always add additional metadata about users elsewhere -- think of how you might do it in a relational database.
> (This isn't just an academic problem - the problem of trying to evolve fields over time is the reason why Protobufs got rid of the idea of a "required" field.)
Protobufs is the poster boy of bad reinvention. ASN.1 got all these things right over a lot of time, and instead of taking the best of it and leaving out the worst of it, everyone is constantly reinventing ASN.1 badly. And yes, ASN.1's evolution was "academic" in many ways, and its authors blazed trails. ASN.1 never had a "required" anything, but it did (and does) have an OPTIONAL keyword.
The reason I mention extensibility above is that ASN.1 has been through the whole academic study of extensibility over several decades:
- since the original encoding rules were
tag-length-value, in the beginning you
could just add fields as long as you
knew the recipient could handle them
(e.g., by ignoring unknown fields)
- when that proved unsatisfying they
added extensibility markers for
denoting "here go extensions" vs
"no extensions allowed", and "these
are version 2 extension fields",
and so on, and not just fields but
also things like INTEGER ranges,
enums, etc.
- they also put a lot of effort into
formalizing the use of "typed holes"
(things like {extension-type-ID,
<encoded-value-of-that-type>}),
and they did this pretty much before
any other schemes.
(The wikipedia page on comparing
serialization schemes[0] refers to
"typed holes" as "references", FYI.)
Extensibility is fairly well covered in many serialization formats now, like XML for example, but still fairly poorly covered in others.
In SQL and relational systems in general one can always add additional fields via tables to JOIN on, and often by adding columns to existing tables.
Extensibility is a big deal, and serious systems will have had serious thought put into it.
[0] https://en.wikipedia.org/wiki/Comparison_of_data-serialization_formats