Skip to content

Comment on Dynamic Languages Are Static Languages (2011)

Comments

You can apply this same idea to serialization formats. JSON doesn't have a schema. On the other hand, you can think of all JSON values as belonging to this Protocol Buffers schema:

    message JsonArray {
      repeated JsonValue value = 1;
    }

    message JsonObject {
      map<string, JsonValue> properties = 1;
    }

    message JsonValue {
      oneof value {
        JsonObject object_value = 1;
        JsonArray array_value = 2;
        bool is_null = 3;
        bool boolean_value = 4;
        string string_value = 5;

        // Represented as a string because JSON doesn't restrict the
        // range/precision of numbers.
        string number_value = 6;
      }
    }

So, this is something I've been thinking about recently: do you gain much by using Protocol Buffers (et al) for a client-side web application's communication with a server? Having JSON/XMLHttpRequest in the browser by default is such a boon that it'd have to be a lot better as a serialisation format for it to be worth it, but that might actually be the case?

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.