liveBook · Manning

Boolean

As explained in API Design Patterns

A boolean is a primitive data type whose value is one of two logical states, typically true or false.

A boolean is a primitive value with two logical states: true and false. Use it for flags and straightforward yes-or-no questions, such as whether a chat room is archived or allows chatbots. section 5.2

Choose boolean fields deliberately:

  • Prefer positive names such as allowChatbots or enableFeature, so true expresses the permitted or enabled condition and avoids double negatives. section 5.2 section 5.9
  • Do not replace a developing category or lifecycle with many independent flags. Use a more expressive structure or state field when several values may emerge. section 5.2 section 25.3.1
  • Define the meaning of null, undefined, and missing values separately; they may not mean the same thing as false. section 5.9

Soft deletion

A resource can expose deleted: boolean, defaulting to false. Treat the field as output-only: the standard delete method changes it to true, and a custom undelete method changes it back. An ordinary update that includes deleted succeeds without changing the value. section 25.3.1

How API Design Patterns covers it

How deep it goes
Explains representation, naming, missing-value semantics, output-only behavior, and when state fields should replace boolean flags.
Examples
Uses ChatRoom fields for archiving and chatbot access, plus an output-only deleted field for soft deletion.
What you can do after
Apply it via resource APIs by choosing positive flag names, modeling evolving categories explicitly, and enforcing output-only transitions.
How it connects
Connects booleans with flags, null values, undefined values, state fields, state machines, soft deletion, and custom methods.

Also explained in

Compare how 11 books explain boolean →

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.