Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many parameters in C# method are acceptable? [closed]

Tags:

I am new to C# and have to maintain a C# Application. Now I've found a method that has 32 Parameters (not auto-generated code).

From C/C++ I remember the rule of thumb "4 Parameters". It may be an old-fashioned rule rooting back to old 0x86 compilers, where 4 Parameters could be accommodated in registers (fast) or on stack otherwise.

I am not concerned about performance, but I do have a feeling that 32 parameters per functions are not easy to maintain even in C#.

Or am I completely not up to date?

What is the rule of thumb for C#?

Thank you for any hint!

like image 483
Valentin H Avatar asked Sep 14 '12 21:09

Valentin H


1 Answers

There is no general consensus and it depends on who you ask.

In general - the moment readability suffers, there are too many...

Bob Martin says the ideal number of parameters is 0 and that 3 is stretching it.

32 parameters is a massive code smell. It means the class has way too many responsibilities and needs to be refactored. Even applying a parameter object refactoring sounds to me like it would hide a bad design rather than solve the issue.

From Clean Code Tip of the Week #10:

Functions should have a small number of arguments. No argument is best, followed by one, two, and three. More than three is very questionable and should be avoided with prejudice.

like image 84
Oded Avatar answered Oct 23 '22 11:10

Oded