Data clumps happens when two or more data are often passed around the code together.

Data clumps might be an indicator of something wrong, deeper in the application code or architecture.

You need to check if one data in isolation can make sense or no, to identify data clumps.

Benefits of fixing data clumps:

  • functions and methods parameters become shorter
  • avoids code repetition
  • makes codes shorter and more readable

Not good:

function calculateDistance(x1, y1, x2, y2)

Better:

class Coordinate {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
}

coordinate1 = new Coordinate(1, 2)
coordinate2 = new Coordinate(3, 4)

function calculateDistance(coordinate1, coordinate2)

Not good:

function calculateLength(start_date, end_date)

Better:

class DateRange {
  constructor(start_date, end_date) {
    ...
  }
}

function calculateLength(dateRange)

Not good:

function welcomeMessage(firstname, lastname, age, job)

Better:

function welcomeMessage(user)