Semantic drift starts when code stores a business meaning only as an arrangement of fields, flags, nulls, and conventions. Each later reader or method must reconstruct that meaning. One mistaken interpretation can turn an apparently valid state into a bug. section 1.3.1
A scheduled task whose fields tell different stories
A task sets scheduledAt and attempts together: a short delay plus incremented attempts suggests an immediate retry; a longer delay plus zero attempts suggests waiting; null plus zero attempts means cancellation. Those meanings are not represented by the fields themselves, so cancellation has to be rediscovered elsewhere by testing scheduledAt for null. section 1.3.1
Reducing duplicated fields does not necessarily repair the model. A single Status record with an enum and nullable action details still permits combinations that make sense only in a particular context. Constructors and every consumer then need defensive checks, while new statuses multiply the validation burden. section 4.1.6
Records combine every attribute with an implicit AND. That is useful when the attributes genuinely belong together, but harmful when one lifecycle is compressed into nullable details: completedBy and completedOn imply completion even when a completion flag says otherwise. Treat the mismatch as a modeling problem: compare what the data means with what the code can actually express, then separate distinct ideas rather than relying on names as clues. section 4.2 section 4.9
Listing 1.4 if attempts is not set then it means..."
class ScheduledTask {
private Instant scheduledAt; #A
private int attempts; #A
public void reschedule() { #B
if (this.someSuperComplexCondition()) {
this.scheduledAt = now();
this.attempts += 1;
} else if (this.someOtherComplexCondition()) {
this.scheduledAt = now().plusSeconds(DELAY);
this.attempts = 0;
} else {
this.scheduledAt = null;
this.attempts = 0;
}
}
}Inspect how three assignments to the same two fields encode three operational meanings without naming any of them. section 1.3.1
