Replace long parameter lists with parameter objects
✓Works with OpenClaudeYou are a refactoring expert. The user wants to replace long parameter lists with parameter objects to improve code readability and maintainability.
What to check first
- Count the number of parameters in your function signature — if it's more than 3-4, it's a candidate for refactoring
- Identify which parameters are frequently passed together across multiple function calls
- Check if parameters share logical grouping (e.g., coordinates, user details, configuration settings)
Steps
- Identify the function with a long parameter list that you want to refactor
- Create a new object type (class, interface, or type alias) to hold the related parameters
- Group logically related parameters into the new object — for example,
x, y, zbecome aPointobject withx,y,zproperties - Replace the individual parameters in the function signature with a single parameter of the new object type
- Update all function calls to pass an object instead of individual arguments
- Update the function body to access properties from the parameter object (e.g., change
xtoparams.x) - Add default values to the object type if some parameters are optional
- Consider adding a constructor or factory function for common parameter combinations
Code
// BEFORE: Long parameter list
function createUser(firstName, lastName, email, age, address, city, zipCode, country, phone) {
const user = {
firstName,
lastName,
email,
age,
address,
city,
zipCode,
country,
phone
};
validateEmail(email);
return user;
}
createUser("Jane", "Doe", "jane@example.com", 30, "123 Main St", "Boston", "02101", "USA", "555-1234");
// AFTER: Parameter object
class UserParams {
constructor(firstName, lastName, email, age, address, city, zipCode, country, phone = null) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.age = age;
this.address = address;
this.city = city;
this.zipCode = zipCode;
this.country = country;
this.phone = phone;
}
}
function createUser(params) {
const user = {
firstName: params.firstName,
lastName: params.lastName,
email: params.email,
age: params.age,
address: params.address,
city: params.city,
zipCode: params.zipCode,
country: params.country,
phone: params.phone
};
validateEmail(params.email);
return user;
}
// Or using TypeScript/modern object syntax:
function createUser({ firstName, lastName, email, age, address, city, zipCode, country, phone = null }) {
const user = { firstName, lastName, email, age, address, city, zipCode, country
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Refactoring Skills
Other Claude Code skills in the same category — free to download.
Extract Function
Extract code blocks into well-named functions
Rename Symbol
Safely rename variables, functions, classes across codebase
Remove Dead Code
Find and remove unused code
Simplify Conditionals
Simplify complex if/else chains and nested conditions
Extract Component
Extract UI code into reusable components
DRY Refactor
Find code duplication and extract shared logic
Promise to Async
Convert Promise chains to async/await
Class to Functions
Convert class-based code to functional style
Want a Refactoring skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.