liveBook · Manning

Heterogeneous string map

As explained in Data-Oriented Programming: Reduce software complexity

A heterogeneous map is a map whose values can have different types or shapes.

A heterogeneous string map is a map whose string-keyed values can have different types or shapes. In data-oriented programming (DOP), it represents a record: field names and value types are not fixed in a class. That trade-off gives data flexibility and genericity while reducing compile-time safety. section 3.2 section 3.6

Keep the two map roles distinct:

  • Use a heterogeneous map for a record with known field names and values of different shapes, such as an ISBN, title, year, author identifiers, and book items. section 12.1
  • Use a homogeneous map for an index with unknown field names and values sharing a common shape, such as booksByIsbn or authorsById. section 12.1
  • Access nested information through paths and generic functions; this keeps code weakly dependent on the data representation and makes field changes easier to absorb. section 3.6

A library record without a Book class

A Watchmen record can combine strings, a number, an array of author identifiers, and an array of nested book-item maps. The same shape can be written as a generic map in JavaScript or Java, rather than instantiated through Book and BookItem classes.

Listing 3.1 An instance of a Book record represented as a map
{
  "isbn": "978-1779501127",
  "title": "Watchmen",
  "publicationYear": 1987,
  "authors": ["alan-moore", "dave-gibbons"],
  "bookItems": [
    {
      "id": "book-item-1",
      "libId": "nyc-central-lib",
      "isLent": true
    },
    {
      "id": "book-item-2",
      "libId": "nyc-central-lib",
      "isLent": false
    }
  ]
}

Inspect the complete nested record to see how primitive values, positional collections, and nested maps compose one heterogeneous structure. section 3.2

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Defines record and index distinctions, demonstrates nested representations, and stops short of preserving compile-time field safety.
Examples
Uses a Watchmen library record, nested book items, JavaScript and Java maps, and catalog schemas for books and authors.
What it assumes
Assumes basic maps, records, collections, and data types while defining heterogeneous and homogeneous maps explicitly.
What you can do after
Apply it via generic functions and JSON Schema to represent, navigate, and validate evolving records.
How it connects
Connects records with homogeneous maps, indexes, positional collections, information paths, generic functions, and JSON Schema.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.