liveBook · Manning

Homogeneous string map

As explained in Data-Oriented Programming: Reduce software complexity

A homogeneous map is a map whose values all have the same type or kind.

A homogeneous string map is an index whose keys are strings and whose values share one type or common shape. Unlike a record, it has unknown field names and consistently shaped values: booksByIsbn maps keys to Book values, while authorsById maps keys to Author values. section 3.2 section 12.1

Keep the distinction clear:

  • Use a homogeneous string map for indexes, where elements are accessed by string keys and values have a common shape. section 12.1
  • Use a heterogeneous string map for records, where field names are known and values may have different types. section 3.2
  • Accept a tradeoff: generic maps increase flexibility and genericity while reducing the safety associated with compile-time fields. section 3.6

Catalog indexes

A catalog can contain booksByIsbn and authorsById. Each is a string-keyed map with no predefined item names: every value under booksByIsbn follows bookSchema, and every value under authorsById follows authorSchema. The map structure stays generic while the value schema supplies the expected shape. section 12.1 section 3.2

Listing 12.5 The JSON Schema for an homogeneous map with values as numbers
{
  "type": "object",
  "additionalProperties": {"type": "number"}
}

Inspect the JSON Schema pattern: declare an object and use additionalProperties to require every unspecified property value to match one schema. section 12.1

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Defines the map distinction and shows JSON Schema validation through additionalProperties, stopping short of implementation internals.
Examples
Uses catalog indexes and a numeric homogeneous-map schema as concrete examples.
What it assumes
Assumes familiarity with maps and indexes while distinguishing records from zero.
What you can do after
Apply it via JSON Schema by validating every additional property against one value schema.
How it connects
Connects indexes with records, heterogeneous maps, JSON Schema, and data validation.

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.