Code Smell 10: Functions With Too Many Arguments

Written by mcsee | Published 2025/12/21
Tech Story Tags: clean-code | code-refactoring | refactor-legacy-code | object-oriented-design | software-design-principles | extract-class-refactoring | method-object-pattern | maintainable-code

TLDRFunctions with long argument lists hide domain knowledge, reduce reuse, and increase coupling. Refactoring parameters into cohesive domain objects restores clarity, intent, and maintainability.via the TL;DR App

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.



Written by mcsee | I’m a sr software engineer specialized in Clean Code, Design and TDD Book "Clean Code Cookbook" 500+ articles written
Published by HackerNoon on 2025/12/21