Functions with a long parameter list are difficult to use because maintainers must figure out the role of each parameter and keep track of their
position.
func setCoordinates(x1: Int, y1: Int, z1: Int, x2: Int, y2: Int, z2: Int) { // Noncompliant
// ...
}
The solution can be to:
- Split the function into smaller ones
// Each function does a part of what the original setCoordinates function was doing, so confusion risks are lower
func setOrigin(x: Int, y: Int, z: Int) {
// ...
}
func setSize(width: Int, height: Int, depth: Int) {
// ...
}
- Find a better data structure for the parameters that group data in a way that makes sense for the specific application domain
struct Point { // In geometry, Point is a logical structure to group data
var x:String
var y:String
var z:String
}
func setCoordinates(p1: Point, p2: Point) {
// ...
}
This rule raises an issue when a function has more parameters than the provided threshold.