What is a data clump and how does EK9 detect it?
← Code Quality · Ref: Q962
A data clump occurs when 3 or more callables share 4 or more parameters with the same types and names. EK9 detects this at compile time and raises E11053.
WHY THIS MATTERS
Repeated parameter groups signal a missing abstraction. Martin Fowler identified data clumps as a code smell in 'Refactoring' (1999). The repeated parameters should be extracted into a record.
THRESHOLD
- 4 or more parameters with matching types and names
- Shared across 3 or more callables in the same module
THE FIX
Extract a record:
defines record Coordinate latitude Float: 0.0 longitude Float: 0.0 altitude Float: 0.0 heading Float: 0.0
Then pass the record instead of 4 separate parameters.
THIS EXAMPLE
Two functions share 4 Float parameters (latitude, longitude, altitude, heading). With only 2 functions sharing the clump, this is below the threshold of 3.
The typicalError mutation adds a third function with the same 4 parameters, triggering E11053.
See Q313 for code smells. See Q310 for quality overview.
Example
defines module qa.quality.dataclump defines function <?- Computes a distance metric from navigation coordinates. Uses 4 Float parameters: latitude, longitude, altitude, heading. -?> computeDistance() -> latitude as Float longitude as Float altitude as Float heading as Float <- result as Float: latitude + longitude + altitude + heading <?- Calculates a heading adjustment from the same navigation coordinates. Same 4 parameters as computeDistance, but only 2 functions share them. Below the threshold of 3 callables. -?> calculateHeading() -> latitude as Float longitude as Float altitude as Float heading as Float <- result as Float: heading + latitude + longitude + altitude defines program DataClumpDemo() stdout <- Stdout() distance <- computeDistance(latitude: 51.5, longitude: 0.12, altitude: 100.0, heading: 270.0) bearing <- calculateHeading(latitude: 51.5, longitude: 0.12, altitude: 100.0, heading: 270.0) stdout.println(`Distance: ${distance}`) stdout.println(`Bearing: ${bearing}`)
Common mistakes
E11053 — Adding a third function with the same 4 Float parameters (latitude, longitude, altitude, heading) triggers E11053. Extract a Coordinate record instead. See ek9 -h E11053 for details.
Incorrect:
calculateHeading()
->
latitude as Float
longitude as Float
altitude as Float
heading as Float
<- result as Float: heading + latitude + longitude + altitude
estimateArrival()
->
latitude as Float
longitude as Float
altitude as Float
heading as Float
<- estimate as Float: latitude + longitude + altitude + heading
Correct:
calculateHeading()
->
latitude as Float
longitude as Float
altitude as Float
heading as Float
<- result as Float: heading + latitude + longitude + altitude
Other ways to ask this
- What triggers E11053 DATA_CLUMP_DETECTED?
- How many functions sharing parameters trigger the data clump error?
- How do I extract a record from repeated parameters?
Coming from another language?
Java: data clumps detected only by SonarQube or PMD (optional). Python: no detection. C++: no detection. Go: convention recommends structs but not enforced. EK9: compile-time detection when 3+ callables share 4+ matching parameters.
Keywords: quality, parameter, E11053, data, smell, function, record, clump, refactoring, extract