liveBook · Manning

Data-oriented programming

As explained in The Art of Code

A programming paradigm that models data as simple immutable structures and expresses behavior through standalone functions operating on that data.

A constructor call can hide more than it reveals: `new User("John", 180, 70)` gives no clue what the numbers mean. Data-oriented programming starts by making the data model explicit, so the purpose of the behavior built around it is easier to see. section 4.0

In the full paradigm, data consists of simple immutable structures, and behavior lives in standalone functions that operate on them, often without encapsulation, inheritance, or internal state. This separation can make logic more predictable and easier to test. In an object-oriented language, a selective data-oriented approach is often more practical than forcing the entire paradigm onto every problem. section 4.2

Make the values tell the story

Compare `new User("John", 180, 70)` with `new PhysicalProfile("John", new WeightInPounds(180), new HeightInInches(70))`. The second call identifies the concept and the units at the point of use. That precision is worthwhile when it prevents confusion; it is not a reason to create a new type for every ordinary value. section 4.0 section 4.3

When a data model obscures intent:

  • Identify the central data concept, then name values that represent units, identity, state, ranges, or categories. section 4.3
  • Keep validation near the structure it protects, and prefer immutability when values need not change. section 4.3
  • Use small explicit carriers or categories where they clarify the call site; avoid extra types and nesting that add more complexity than meaning. section 4.3

The working rule is to model the problem through its data first, then let behavior organize around that model. Adopt only the structure that makes intent clearer. section 4.4 section 4.3

How The Art of Code covers it

How deep it goes
Defines the full paradigm, then develops selective modeling principles rather than a complete standalone-function architecture.
Examples
Contrasts an ambiguous `User` constructor with a `PhysicalProfile` whose weight and height carry explicit units.
What it assumes
Assumes familiarity with object-oriented data classes and mutability while defining data-oriented programming before recommending selective use.
What you can do after
Practice/perform it by identifying ambiguous values, naming meaningful data concepts, and choosing immutable carriers where they improve clarity.
How it connects
Connects immutable data and standalone functions with object-oriented encapsulation, domain modeling, records, and pattern matching.

Also explained in

Compare how 3 books explain data-oriented programming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Code. The section links point to the parts of the book it draws on.