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!
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: