The second bug involved the "Commutativity Fallacy." In John’s algorithm, he suggested that Bread + Butter + Cheese = Sandwich. In mathematics, addition is commutative, meaning the order does not change the result. However, physical assembly—and software execution—is rarely commutative. Placing butter underneath the bread results in a greasy plate and a structural failure rather than a sandwich. The experiment highlighted that developers cannot use mathematical shorthand to hide unstated physical or logical actions; the sequence of operations is as vital as the operations themselves.
The third and perhaps most architectural flaw was the "Container Leak." John’s final step combined the completed sandwich with the plate to produce a "result." From an engineering standpoint, this conflated the data payload (the sandwich) with the execution environment or runtime infrastructure (the plate). If a user were to "consume" the result, they would, according to this logic, also consume the plate. This type of architectural blurring in software leads to memory leaks and "dirty" architecture, where the data and the systems that carry it become inseparable and impossible to manage independently.
The Birth of State and Command-Query Separation
Following the failure of the first attempt, the experiment moved into its second phase: inventing a mini-language to describe the world. John was forced to separate ingredients from tools and define operational verbs that triggered "state transitions."
In this context, "state" was defined as the condition or configuration of an entity at a specific point in time. The apprentice learned that actions in a system do not just "do things"; they change the state of the objects involved. This realization led to the "Bank Test," where the model was applied to pure information rather than physical objects.
By analyzing a bank account with a balance of $5,000 and an "Active" status, John examined four operations: depositing, withdrawing, checking the balance, and closing the account. During this process, he noticed a crucial distinction. While withdrawing money changed the balance, checking the balance left the state of the account entirely unchanged.
This observation led John to independently discover Command-Query Separation (CQS), a pillar of professional software design. He categorized operations into two distinct groups: Commands and Queries. Commands, such as a withdrawal, are mutations that change state and produce side effects. Queries, such as checking a balance, are observations that read state but produce zero side effects. Understanding this distinction is vital for creating predictable, testable software, yet it is a concept often skipped in syntax-heavy tutorials.
The 100-Cars Dilemma and the Scalability of Classes
The final conceptual hurdle was the problem of scalability, framed as the "100-Cars Dilemma." John was asked to design a racing simulation where each car has speed, fuel, and an engine, and can perform actions like accelerating or braking. The challenge was to design this for 100 cars without writing the acceleration logic 100 separate times.
