This story on HackerNoon has a decentralized backup on Sia.
Transaction ID: 6KBZgOHmL4IWhUiUoSxlvcgU4vcXmlD3wm7_-8Bde9g
Cover

Code Smell 10: Functions With Too Many Arguments

Written by @mcsee | Published on 2025/12/21

TL;DR β€”
Functions with long argument lists hide domain knowledge, reduce reuse, and increase coupling. Refactoring parameters into cohesive domain objects restores clarity, intent, and maintainability.

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 βš™οΈ

Read the articles below for refactorings.



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         
        ) {
    }
}

Right πŸ‘‰

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


Steal My Prompts (Without Proper Instructions)πŸ“΅

Steal My Prompts (With Specific Instructions) πŸ‘©β€πŸ«

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.

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-vii-8dk31x0

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-iii-t7h3zkv

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xviii


Lead photo by Tobias Tullius on Unsplash

This article is part of the CodeSmell Series.


[story continues]


Written by
@mcsee
I’m a sr software engineer specialized in Clean Code, Design and TDD Book "Clean Code Cookbook" 500+ articles written

Topics and
tags
clean-code|code-refactoring|refactor-legacy-code|object-oriented-design|software-design-principles|extract-class-refactoring|method-object-pattern|maintainable-code
This story on HackerNoon has a decentralized backup on Sia.
Transaction ID: 6KBZgOHmL4IWhUiUoSxlvcgU4vcXmlD3wm7_-8Bde9g