Code Smell 10 - Too Many Arguments

Code Smell 10 - Too Many Arguments

Leader posted 5 min read

Objects or Functions need too many arguments to work.

TL;DR: Don't pass more than three arguments to your functions.

Problems

  • Low maintainability
  • Low Reuse
  • Coupling

Solutions

  1. Find cohesive relations among arguments

  2. Create a "context".

  3. Consider using a Method Object Pattern.

  4. Avoid "basic" Types: strings, arrays, integers, etc. Think on objects.

Refactorings ⚙️

https://maximilianocontieri.com/refactoring-007-extract-class

https://maximilianocontieri.com/refactoring-010-extract-method-object

https://maximilianocontieri.com/refactoring-034-reify-parameters

Context

When you add arguments to make a function work, you encode knowledge in position and order.

You force your callers to remember rules that belong to the domain.

When you do this, you move behavior away from meaningful objects, and you replace intent with mechanics.

Sample Code

Wrong

public class Printer {   
  void print(String documentToPrint, 
           String papersize,
           String orientation, 
           boolean grayscales,
           int pagefrom,
           int pageTo,
           int copies,
           float marginLeft,
           float marginRight,
           float marginTop,
           float marginBottom         
        ) {
    }
}
final public class PaperSize { }
final public class Document { }
final public class PrintMargins { }
final public class PrintRange { }  
final public class ColorConfiguration { }
final public class PrintOrientation { }
// Class definition with methods and properties omitted for simplicity

final public class PrintSetup {
    public PrintSetup(PaperSize papersize,
           PrintOrientation orientation, 
           ColorConfiguration color,
           PrintRange range,
           int copiesCount,
           PrintMargins margins
           ) {}
}

final public class Printer {   
  void print(
         Document documentToPrint, 
         PrintSetup setup        
        ) {
    }
}

Detection

Most linters warn when the arguments list is too large.

You can also detect this smell when a function signature grows over time.

Exceptions

Operations in real-world needing not cohesive collaborators.

Some low-level functions mirror external APIs or system calls.

In those cases, argument lists reflect constraints you cannot control.

Tags ️

  • Bloaters

Level

[X] Beginner

Why the Bijection Is Important ️

Good design keeps a clear bijection between concepts in the program and concepts in the MAPPER.

When you spread a concept across many arguments, you break that mapping.

You force callers to assemble meaning manually, and the model stops representing the domain.

AI Generation

AI generators often create this smell.

They optimize for quick success and keep adding parameters instead of creating new abstractions.

AI Detection

AI generators can fix this smell when you ask for value objects or domain concepts explicitly.

Try Them!

Remember: AI Assistants make lots of mistakes

Suggested Prompt: Refactor this function by grouping related parameters into meaningful domain objects and reduce the argument list to one parameter

Without Proper Instructions With Specific Instructions
ChatGPT ChatGPT
Claude Claude
Perplexity Perplexity
Copilot Copilot
You You
Gemini Gemini
DeepSeek DeepSeek
Meta AI Meta AI
Grok Grok
Qwen Qwen

Conclusion

Relate arguments and group them.

Always favor real-world mappings. Find in real-world how to group the arguments in cohesive objects.

If a function gets too many arguments, some of them might be related to the class construction. This is a design smell too.

Relations ❤️

https://maximilianocontieri.com/code-smell-34-too-many-attributes

https://maximilianocontieri.com/code-smell-13-empty-constructors

https://maximilianocontieri.com/code-smell-87-inconsistent-parameters-sorting

Credits

Photo by Tobias Tullius on Unsplash


This article is part of the CodeSmell Series.

https://maximilianocontieri.com/how-to-find-the-stinky-parts-of-your-code

1 Comment

0 votes

More Posts

Code Smell 06 - Too Clever Programmer

Maxi Contieri - Dec 5, 2025

Code Smell 03 - Functions Are Too Long

Maxi Contieri - Nov 22, 2025

Code Smell 319 - Hardcoded Stateless Properties

Maxi Contieri - Apr 9

Code Smell 17 - Global Functions

Maxi Contieri - Feb 28

Code Smell 16 - Ripple Effect

Maxi Contieri - Feb 19
chevron_left

Related Jobs

Commenters (This Week)

3 comments
2 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!