liveBook · Manning

Zero value

As explained in API Design Patterns

A zero value is the empty or numerically zero representation that a data format or type uses when no distinct null representation is available.

A zero value is the empty or numerically zero representation used when a type or format has no distinct null or missing state. It often becomes the default, but it cannot show whether the user intentionally chose that value. section 5.2 section 5.3.2

Treat zero values as API design constraints:

  • A Boolean zero value usually means false, so unset and explicitly false become indistinguishable. section 5.2
  • Using zero as a numeric default marker prevents clients from intentionally specifying zero. section 5.3.2
  • Naming a Boolean for the desired zero-value behavior can solve an immediate default problem but locks that default into the field name. section 5.2
  • An empty map can express “no data,” while a null map can request API-selected behavior; do not collapse the two. section 5.7.2

Chat room permissions

Suppose a ChatRoom exposes allowChatbots. If the format supplies only a Boolean zero value, a newly created room receives false whether the user omitted the field or explicitly prohibited chatbots. A negative name such as disallowChatbots can make false produce an intended permissive default, but changing that default later becomes difficult. section 5.2

Listing 5.1 A ChatRoom resource with a Boolean flag
interface ChatRoom {
  id: string;
  // ...                    #1
  archived: boolean;        #2
  allowChatbots: boolean;   #3
}

Inspect the ChatRoom resource shape and its Boolean permission flag. section 5.2

How API Design Patterns covers it

How deep it goes
Explains Boolean, numeric, and map consequences, but defers numeric default handling to serialization design.
Examples
Uses ChatRoom permissions, allowChatbots, disallowChatbots, numeric zero, and empty-versus-null maps.
What it assumes
Assumes basic API fields and serialization, while distinguishing null, missing, empty, and zero values.
What you can do after
Evaluate API defaults for ambiguity, intentional zero values, predictable behavior, and future default changes.
How it connects
Connects zero values to null values, missing values, default values, Boolean fields, numeric fields, and serialization formats.

Also explained in

Compare how 5 books explain zero value →

Related concepts

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