Skip to content

Data Clumps

How to spot groups of values that always travel together through your signatures, and how to turn them into a single object with its own behaviour.

6 min readCode smellBloat

A data clump is a set of values that keeps appearing together: the same two or three parameters in function after function, the same fields side by side in several classes. Each value is meaningless alone. A check-in date without a check-out date tells you nothing, and neither does a latitude without its longitude. The smell is not the parameter count. The problem is that a concept your code relies on has no name and no home. Rules about it, such as validation, comparison and arithmetic, end up copied wherever the loose values land. In an interview, this is one of the easiest smells to point at in a code review exercise, and one of the best openings to show you think in domain concepts rather than primitives.

Signs

How to spot it in a review.

  • The same two or three parameters appear, in the same order, across several function signatures.
  • Several classes or records declare the same group of fields with matching prefixes, such as billingStreet, billingCity, billingZip.
  • Deleting one value from the group would make the others meaningless.
  • The same validation or comparison of the group, such as end > start, is repeated in multiple places.
  • Callers unpack an object only to pass its fields one by one to another function.
  • Parameter names get suffixes like aIn, aOut, bIn, bOut to tell two copies of the group apart.

What it looks like

A typical case, in three languages.

interface Booking {
  cabinId: string;
  checkIn: string; // YYYY-MM-DD
  checkOut: string;
}

const MS_PER_DAY = 86_400_000;

function nightsBetween(checkIn: string, checkOut: string): number {
  return Math.round((Date.parse(checkOut) - Date.parse(checkIn)) / MS_PER_DAY);
}

function overlaps(aIn: string, aOut: string, bIn: string, bOut: string): boolean {
  return aIn < bOut && bIn < aOut;
}

function isAvailable(
  cabinId: string,
  checkIn: string,
  checkOut: string,
  bookings: Booking[],
): boolean {
  return !bookings.some(
    (b) => b.cabinId === cabinId && overlaps(checkIn, checkOut, b.checkIn, b.checkOut),
  );
}

function quote(
  cabinId: string,
  checkIn: string,
  checkOut: string,
  nightlyRateCents: number,
  bookings: Booking[],
): number {
  if (checkOut <= checkIn) {
    throw new Error("checkOut must be after checkIn");
  }
  if (!isAvailable(cabinId, checkIn, checkOut, bookings)) {
    throw new Error(`Cabin ${cabinId} is taken`);
  }
  const nights = nightsBetween(checkIn, checkOut);
  let total = nights * nightlyRateCents;
  if (nights >= 7) {
    total -= Math.floor(total / 10);
  }
  return total;
}

const existing: Booking[] = [{ cabinId: "pine-3", checkIn: "2025-06-01", checkOut: "2025-06-05" }];
console.log(quote("pine-3", "2025-06-05", "2025-06-12", 14_500, existing)); // 91350

This is the quoting module of a cabin rental site. The pair checkIn and checkOut travels through every signature and is stored as two loose fields on Booking. overlaps needs four strings with awkward suffixes, and only quote checks that the range is valid, so isAvailable happily accepts a reversed range. The fix is a StayDates object built once and validated in its constructor, with nights() and overlaps(other) moved onto it. Booking then holds a StayDates, and the signatures shrink to isAvailable(cabinId, stay, bookings) and quote(cabinId, stay, rate, bookings).

Why it happens

How code ends up like this.

  • The concept starts small. A function needs two values, a second function calls the first and forwards them, and nobody stops to name the pair.
  • Primitive types feel cheaper than a new class, especially in languages where declaring one takes boilerplate.
  • Data often arrives as flat columns from a database or flat fields from a form, and that shape leaks inward unchanged.
  • Copying an existing signature is the fastest way to add a new function, so the clump spreads by imitation.

Treatment

The refactorings that cure it, and when to choose each.

Payoff

What you get once it's gone.

  • Signatures get shorter, and argument-order mistakes like swapping check-in and check-out become impossible or caught at construction.
  • Validation happens once in a constructor instead of being remembered, or forgotten, in each function.
  • Behaviour such as counting nights or detecting overlaps gets a natural home, which removes duplicated logic.
  • The code speaks the domain's language: a reader sees StayDates and knows exactly what is meant.

When to leave it

Sometimes it's not worth fixing.

  • The values appear together in only one or two places and are not likely to spread. A new class would cost more than it saves.
  • A hot loop where allocating an object per call has measured cost, for example millions of coordinate pairs in a numeric kernel. Keep primitives there and wrap them at the boundary.
  • The group is coincidental: values that happen to sit side by side today but change for different reasons and have no shared rules.

Common questions

Short answers to the usual doubts.

How do I tell a data clump from a function that simply has many parameters?

Apply the deletion test. Remove one value from the group and ask whether the rest still make sense. If check-out is meaningless without check-in, they form a clump. A long parameter list of unrelated values is a different smell, and the fix there is usually splitting the function, not bundling the arguments.

Is a plain record or dataclass enough, or do I need a full class?

Start with a simple immutable record; that alone fixes the signatures. The real payoff comes when you move behaviour onto it: validation in the constructor, and methods like nights() or overlaps(). A record with no behaviour is a good first step, but if the logic stays scattered you have only renamed the problem.

How would I raise this in a code review interview?

Point to the repeated parameters, name the missing concept, and show the cost: duplicated validation and the reversed-range bug in isAvailable. Then propose the order of steps: introduce the parameter object, migrate callers, move behaviour onto it. Interviewers look for the concrete bug risk and an incremental plan, not just the label.

Should the new object be mutable?

Usually not. Clumps tend to be value-like: two stays with the same dates are interchangeable. Making the object immutable means you can validate once at construction and trust it everywhere after, and you can share instances without defensive copies.