Hacker News new | ask | show | jobs
by skybrian 501 days ago
Thanks for the clarification! That sounds about as evolvable as JSON or any system that uses string keys (like HTTP headers).

Protobufs have an extra level of indirection built in: code refers to fields using names, but numbers are sent on the wire. Without convenient access to field numbers, they can’t as easily be hard-coded. This also strongly encourages using the schema file for most tasks. With protobufs (or similar), any user-friendly editor will need a schema to make sense of the data.

JSON-like systems and protobufs have opposite design goals: encouraging versus discouraging schemaless data access.

1 comments

There are no string keys in the Person example above. You could add some, though, or use numbers instead with the same host-language API:

  Person = <person @name String @address Address>
as above, or

  Person = <person {
    @name "name": String
    @address "address": Address
  }>
or

  Person = {
    @name 1: String
    @address 2: Address
  }
etc. all produce the same host-language record, e.g. in TypeScript

  export type Person = {
    name: String,
    address: Address,
  };