有多少参数在C#中的方法是可以接受的? [英] How many parameters in C# method are acceptable?

查看:116
本文介绍了有多少参数在C#中的方法是可以接受的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的C#和必须保持一个C#应用程序。
现在我发现,有32个参数(不自动生成的代码)的方法。

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).

从C / C ++我记得拇指法则4参数。这可能是一个老式的规则生根回到老0x86可以编译器,其中4参数可在寄存器(快速)被安置或以其他方式堆栈。

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.

我不关注关于性能,但我有一种感觉,每个功能的32个参数是不易保持,甚至在C#。

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?

什么是经验的C#的规则?

What is the rule of thumb for C#?

感谢您的任何暗示!

推荐答案

有没有普遍的共识,这取决于谁你问

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

在一般 - 瞬间可读性受到影响,有太多的...

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

鲍勃·马丁说的参数理想的数字是0和3拉伸。

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

32个参数是一个庞大的代码味道。这意味着该类有太多的责任,需要进行重构。即使应用参数对象重构听起来好像它会躲在一个不好的设计,而不是解决问​​题。

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.

#周10 <清洁代码提示/一>:

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.

这篇关于有多少参数在C#中的方法是可以接受的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆