49Data Lens Part 1
Fit: evaluating our encoding
We have lots of options for how to encode our models. We
need some way to compare them. Each option is slightly
different. We need some way to know which ones are bet-
ter for our model.
The secret is that there is no one way to evaluate them.
Why? Software design is hard. It’s multidimensional. It’s
too dependent on context for any simple scheme to work
every time.
This book is full of lenses, and each lens gives us a dif-
ferent way to evaluate our options. Here in the data lens,
we are going to use a concept called t.
Let’s evaluate the t of a simplied coffee—one that has
only size and roast. To evaluate the t, we need to count
the number of states in the model.
Counting the states in a combination
Counting the states in a TypeScript object type
X
=
=
Our coffee is a combination
of two alternatives, each
with three options. When
counting the states of a
combination, we multiply
the states of the compo-
nents. So in this case, 3 siz-
es times 3 roasts equals 9
possible combinations.
We encode a coffee as a
TypeScript object type. To
count the states, we mul-
tiply the states of the two
components. In this case, 3
sizes times 3 roasts equals
9 possible states.
Both the model and the code allow the same number of
types. This is very important. We’ll call that perfect t, and
we’ll see this graphically on the next page. In addition, the
correspondence between the model and code are clear.
type Coffee = {
size : Size;
roast: Roast;
};
"super",
"raw"
"mega",
"raw"
"galactic",
"raw"
"super",
"burnt"
"mega",
"burnt"
"galactic",
"burnt"
"super",
"charcoal"
"mega",
"charcoal"
"galactic",
"charcoal"