C#术语问题 [英] C# terminology questions

查看:68
本文介绍了C#术语问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我还没能找到以下

种方法的正确(共同商定)名称。


类(静态)方法:

c1)返回值,不修改其参数的内容和

不改变类的状态(类访问器?)

c2)返回值,不修改其参数的内容和

更改类的状态(类mutator?)

c3)返回值,修改其参数的内容和

不会改变类的状态( class?)

c4)返回值,修改其参数的内容和

改变类的状态(类mutator?)

c5)没有返回值,没有修改其论点的内容和

不会改变课堂的状态(没用?)

c6)没有返回值,没有修改其论点的内容和

改变类的状态(类mutator?)

c7)没有返回值,修改其参数的内容和

没有改变类的状态(类?)

c8)没有返回值,修改其参数的内容和

改变类的状态(类mutator?)

实例方法:

i1)返回值,不修改其参数的内容和

不不改变实例的状态(实例访问器?)

i2)返回值,不修改其参数的内容和

更改实例的状态(实例mutator?)

i3)返回值,修改其参数的内容和

不会改变实例的状态(实例) ?)

i4)返回值,修改其参数的内容和

更改实例的状态(实例mutator?)

i5)没有回报价值,不会改变y它的论点和

的内容是不是改变了实例的状态(没用?)

i6)没有返回值,没有'修改其参数的内容和

更改实例的状态(实例mutator?)

i7)没有返回值,修改内容它的参数和

不会改变实例的状态(实例?)

i8)没有返回值,修改其内容参数和

改变实例的状态(实例mutator?)


任何想法在哪里找到用C#定义的术语(和/或。 NET)

上下文?很高兴知道从业者使用的是什么样的非官方名称




此外,在什么样的情况下使用这些方法是可以接受的

修改其参数的内容(c3,c4,c7,c8,i3,i4,i7,i8)?

Ron

Hi,

I haven''t been able to find proper (commonly agreed) names for the following
kinds of methods.

Class (static) methods:
c1) returns value, doesn''t modify the content of its argument(s) and
doesn''t change the state of class (class accessor?)
c2) returns value, doesn''t modify the content of its argument(s) and
changes the state of class (class mutator?)
c3) returns value, modifies the content of its argument(s) and
doesn''t change the state of class (class ?)
c4) returns value, modifies the content of its argument(s) and
changes the state of class (class mutator?)
c5) doesn''t return value, doesn''t modify the content of its argument(s) and
doesn''t change the state of class (useless?)
c6) doesn''t return value, doesn''t modify the content of its argument(s) and
changes the state of class (class mutator?)
c7) doesn''t return value, modifies the content of its argument(s) and
doesn''t change the state of class (class ?)
c8) doesn''t return value, modifies the content of its argument(s) and
changes the state of class (class mutator?)
Instance methods:
i1) returns value, doesn''t modify the content of its argument(s) and
doesn''t change the state of instance (instance accessor?)
i2) returns value, doesn''t modify the content of its argument(s) and
changes the state of instance (instance mutator?)
i3) returns value, modifies the content of its argument(s) and
doesn''t change the state of instance (instance ?)
i4) returns value, modifies the content of its argument(s) and
changes the state of instance (instance mutator?)
i5) doesn''t return value, doesn''t modify the content of its argument(s) and
doesn''t change the state of instance (useless?)
i6) doesn''t return value, doesn''t modify the content of its argument(s) and
changes the state of instance (instance mutator?)
i7) doesn''t return value, modifies the content of its argument(s) and
doesn''t change the state of instance (instance ?)
i8) doesn''t return value, modifies the content of its argument(s) and
changes the state of instance (instance mutator?)

Any ideas where to find such terminology defined in C# (and/ or .NET)
context? It would be good to know also what kind of unofficial names are
used by practitioners?

Also in what kind of situations it is acceptable to use such methods which
modifies the content of its argument(s) (c3, c4, c7, c8, i3, i4, i7, i8)?
Ron

推荐答案

我认为c5没用。例如,一种方法,其唯一目的是发送电子邮件
。它没有返回任何东西,它没有修改它的

参数,因为它只是用它们发送一封电子邮件,它并没有改变

它所处的阶级状态,因为那是无关紧要的。


我不知道这些方法的官方名称,但我有

从不遇到了必须给它们命名的情况。

毕竟,这些只是概念,是否真的需要标记每种类型的方法?


修改其参数的方法可以是更新数据集中所有

行以在列中具有特定值的方法。


或者是一个接受asp.net控件的类,并在

上设置一个特定的属性来控制一个值(也许它有一些逻辑用于

确定此值)。


或者,给.NET框架示例,Array类的Sort方法。它
接受一个数组作为参数排序,然后对其进行排序。在

方法调用之后,参数已被排序。


" Ron Bullman" < RO ********* @ mail.com>在消息中写道

新闻:OW ************** @ TK2MSFTNGP11.phx.gbl ...
I don''t think c5 is useless. For example, a method whose sole purpose it is
to send out an email. It doesn''t return anything, it doesn''t modify its
argument because it simply uses them to send an email, and it doesn''t change
the state of the class it is in, because that is irrelevant.

I do not know the official names for these kinds of methods, but I have
never encountered a situation where it has been necessary to name them.
After all, these are just concepts, is there really a need to label each
type of method?

Methods that modify its arguments could be a method that updates all the
rows in a dataset to have a particular value in a column.

Or a class that takes an asp.net control, and sets a particular property on
that control to a value (perhaps there is some logic that it uses to
determine this value).

Or, to give a .NET framework example, the Sort method of the Array class. It
accepts an array to sort as the argument, and then sorts it. After the
method call, the argument has been sorted.

"Ron Bullman" <ro*********@mail.com> wrote in message
news:OW**************@TK2MSFTNGP11.phx.gbl...

以下各种方法我都无法找到
的正确(通常同意)名称。

类(静态)方法:
c1 )返回值,不修改其参数的内容并且
不会改变类的状态(类访问器?)
c2)返回值,不修改它的参数的内容和
改变了类的状态(类mutator?)
c3)返回值,修改其参数的内容并且
不会改变类的状态(类?)
c4)返回值,修改其参数的内容和
改变类的状态(类mutator?)
c5)doesn'不返回值,不修改其参数的内容
并且不会改变类的状态(没用?)
c6)没有返回值,没有不要修改它的内容s参数
并更改类的状态(类mutator?)
c7)没有返回值,修改其参数的内容并且
不会'' t改变类的状态(类?)
c8)没有返回值,修改其参数的内容和
改变类的状态(类mutator?)
实例方法:
i1)返回值,不修改其参数的内容并且
不会改变实例的状态(实例访问器?)
i2 )返回值,不修改其参数的内容和
更改实例的状态(实例mutator?)
i3)返回值,修改其参数的内容并且
不会改变实例的状态(实例?)i4)返回值,修改其参数的内容并改变实例的状态(实例mutator? )
i5)没有返回值,没有修改其参数的内容
并且没有不改变实例的状态(无用?)i6)没有返回值,不修改其参数
的内容并更改实例的状态(实例) mutator?)
i7)没有返回值,修改其参数的内容并且
不会改变实例的状态(实例?)
i8)不'返回值,修改其参数的内容并改变实例的状态(实例mutator?)

任何想法在哪里找到C#中定义的术语(和/或.NET)
上下文?很高兴知道从业者使用了哪种非官方名称?

在任何情况下都可以使用这样的方法来修改内容它的论点(c3,c4,c7,c8,i3,i4,i7,i8)?

Ron
Hi,

I haven''t been able to find proper (commonly agreed) names for the following kinds of methods.

Class (static) methods:
c1) returns value, doesn''t modify the content of its argument(s) and
doesn''t change the state of class (class accessor?)
c2) returns value, doesn''t modify the content of its argument(s) and
changes the state of class (class mutator?)
c3) returns value, modifies the content of its argument(s) and
doesn''t change the state of class (class ?)
c4) returns value, modifies the content of its argument(s) and
changes the state of class (class mutator?)
c5) doesn''t return value, doesn''t modify the content of its argument(s) and doesn''t change the state of class (useless?)
c6) doesn''t return value, doesn''t modify the content of its argument(s) and changes the state of class (class mutator?)
c7) doesn''t return value, modifies the content of its argument(s) and
doesn''t change the state of class (class ?)
c8) doesn''t return value, modifies the content of its argument(s) and
changes the state of class (class mutator?)
Instance methods:
i1) returns value, doesn''t modify the content of its argument(s) and
doesn''t change the state of instance (instance accessor?)
i2) returns value, doesn''t modify the content of its argument(s) and
changes the state of instance (instance mutator?)
i3) returns value, modifies the content of its argument(s) and
doesn''t change the state of instance (instance ?)
i4) returns value, modifies the content of its argument(s) and
changes the state of instance (instance mutator?)
i5) doesn''t return value, doesn''t modify the content of its argument(s) and doesn''t change the state of instance (useless?)
i6) doesn''t return value, doesn''t modify the content of its argument(s) and changes the state of instance (instance mutator?)
i7) doesn''t return value, modifies the content of its argument(s) and
doesn''t change the state of instance (instance ?)
i8) doesn''t return value, modifies the content of its argument(s) and
changes the state of instance (instance mutator?)

Any ideas where to find such terminology defined in C# (and/ or .NET)
context? It would be good to know also what kind of unofficial names are
used by practitioners?

Also in what kind of situations it is acceptable to use such methods which
modifies the content of its argument(s) (c3, c4, c7, c8, i3, i4, i7, i8)?
Ron



嗨Marina,


感谢您的回复。我的评论内联。


Ron

" Marina" < ZL ******* @ nospam.hotmail.com>在消息中写道

news:uZ ************** @ tk2msftngp13.phx.gbl ...
Hi Marina,

Thanks for your reply. My comments inlined.

Ron
"Marina" <zl*******@nospam.hotmail.com> wrote in message
news:uZ**************@tk2msftngp13.phx.gbl...
我不是认为c5没用。例如,一个方法,其唯一目的是
发送电子邮件。它没有返回任何内容,它没有修改它的
参数,因为它只是使用它们发送电子邮件,并且它不会改变它所在的类的状态,因为那是无关紧要的。


但是这样的方法不应该返回某些指示发送

是否成功?
我不知道这些类型的官方名称方法,但我从来没有遇到过必须给它们命名的情况。
毕竟,这些只是概念,是否真的需要标记每种类型的方法?


但是确实非常重要的概念,我已经看到很多代码,其中

程序员的意图还不够清楚。如果我们(真的)有16个不同类型的行为与这些方法相关联,那么肯定

也可以通过适当的命名来区分它们。虽然我很不确定是否需要所有16个。
修改其参数的方法可以是更新数据集中所有
行的方法在列中具有特定值。


为什么你更喜欢这个而不是实例方法改变它的状态?
或者是一个接受asp.net控制的类,并设置一个特定的属性
on控制到一个值(可能有一些逻辑用于确定这个值)。或者,给.NET框架示例,Array类的Sort方法。
它接受一个数组作为参数排序,然后对其进行排序。在
方法调用之后,参数已经排序。


你在这里推荐的方法AFAIK那里不存在这样的方法

System.Collections.Arraylist
Ron Bullman < RO ********* @ mail.com>在消息中写道
新闻:OW ************** @ TK2MSFTNGP11.phx.gbl ...
I don''t think c5 is useless. For example, a method whose sole purpose it is to send out an email. It doesn''t return anything, it doesn''t modify its
argument because it simply uses them to send an email, and it doesn''t change the state of the class it is in, because that is irrelevant.
But shouldnt such method return somekind of indication wheter the sending
was succesfull or not?
I do not know the official names for these kinds of methods, but I have
never encountered a situation where it has been necessary to name them.
After all, these are just concepts, is there really a need to label each
type of method?
But pretty important concepts indeed and I have seen a lot of code where the
programmers intention havn''t been clear enough. If we (really) have 16
different kind of behaviours associated with the methods then it definitely
would be useful to distinguish them by proper naming as well. Although I''m
not sure at all if all of those 16 is needed.
Methods that modify its arguments could be a method that updates all the
rows in a dataset to have a particular value in a column.
Why would you prefer this instead of instance method mutating its state?
Or a class that takes an asp.net control, and sets a particular property on that control to a value (perhaps there is some logic that it uses to
determine this value).

Or, to give a .NET framework example, the Sort method of the Array class. It accepts an array to sort as the argument, and then sorts it. After the
method call, the argument has been sorted.
What method you are refering here AFAIK there doesen''t exist such method in
System.Collections.Arraylist
"Ron Bullman" <ro*********@mail.com> wrote in message
news:OW**************@TK2MSFTNGP11.phx.gbl...

我无法在
各种方法之后找到


的正确(通常同意)名称。

类(静态) )方法:
c1)返回值,不修改其参数的内容和
不改变类的状态(类访问器?)
c2)返回值,不修改其参数的内容和
改变类的状态(类mutator?)
c3)返回值,修改其参数的内容和
没有改变类的状态(类?)
c4)返回值,修改其参数的内容和
改变类的状态(类mutator?)
c5)没有返回值,没有修改其参数的内容

kinds of methods.

Class (static) methods:
c1) returns value, doesn''t modify the content of its argument(s) and
doesn''t change the state of class (class accessor?)
c2) returns value, doesn''t modify the content of its argument(s) and
changes the state of class (class mutator?)
c3) returns value, modifies the content of its argument(s) and
doesn''t change the state of class (class ?)
c4) returns value, modifies the content of its argument(s) and
changes the state of class (class mutator?)
c5) doesn''t return value, doesn''t modify the content of its argument(s)


并没有改变状态clas s(没用?)
c6)没有返回值,没有修改其参数的内容
doesn''t change the state of class (useless?)
c6) doesn''t return value, doesn''t modify the content of its argument(s)


更改类的状态(类mutator?)
c7)没有返回值,修改其参数的内容并且
不会改变类的状态(类?)
c8)没有返回值,修改其参数的内容和
改变类的状态(类mutator?)
实例方法:
i1)返回值,没有修改其参数的内容和
没有改变实例的状态(实例访问器?)
i2)返回值,不修改其内容它的参数和
改变了实例的状态(实例mutator?)
i3)返回值,修改其参数的内容并且
不会改变状态实例(实例?)
i4)返回值,修改其参数的内容并改变状态o f实例(实例mutator?)
i5)没有返回值,没有修改其参数的内容
changes the state of class (class mutator?)
c7) doesn''t return value, modifies the content of its argument(s) and
doesn''t change the state of class (class ?)
c8) doesn''t return value, modifies the content of its argument(s) and
changes the state of class (class mutator?)
Instance methods:
i1) returns value, doesn''t modify the content of its argument(s) and
doesn''t change the state of instance (instance accessor?)
i2) returns value, doesn''t modify the content of its argument(s) and
changes the state of instance (instance mutator?)
i3) returns value, modifies the content of its argument(s) and
doesn''t change the state of instance (instance ?)
i4) returns value, modifies the content of its argument(s) and
changes the state of instance (instance mutator?)
i5) doesn''t return value, doesn''t modify the content of its argument(s)


没有改变实例的状态(没用?)
i6)没有返回值,没有修改其参数的内容
doesn''t change the state of instance (useless?)
i6) doesn''t return value, doesn''t modify the content of its argument(s)


更改实例的状态(实例mutator?)
i7)没有返回值,修改其参数的内容并且
不会改变状态实例(实例?)
i8)没有返回值,修改其参数的内容和
改变实例的状态(实例mutator?)

>任何想法在哪里找到在C#(和/或.NET)
上下文中定义的术语?很高兴知道从业者使用了哪种非官方名称?

在任何情况下都可以使用这样的方法
修改内容它的论点(c3,c4,c7,c8,i3,i4,i7,
i8)?

Ron
changes the state of instance (instance mutator?)
i7) doesn''t return value, modifies the content of its argument(s) and
doesn''t change the state of instance (instance ?)
i8) doesn''t return value, modifies the content of its argument(s) and
changes the state of instance (instance mutator?)

Any ideas where to find such terminology defined in C# (and/ or .NET)
context? It would be good to know also what kind of unofficial names are
used by practitioners?

Also in what kind of situations it is acceptable to use such methods which modifies the content of its argument(s) (c3, c4, c7, c8, i3, i4, i7, i8)?

Ron




看到这个应用程序到达3.2版后看看有多少

标准名称实际上仍然与它们匹配确实如此。


超过命名约定的标准化导致imho遇到更多问题然后

他们解决了。

你已经达到16涉及仅3

标准组合的名称。如果定义方法

为void,则不返回值。如果参数是ref,它需要一个值

并且会改变它。如果一个参数出来,可能会得到一个值集。对于人们可以理解的方法,使用常见的

感知名称。并且最后但不是

最少使用那个可爱的///语法来写关于

事物_actually_的内容的可读评论。


强类型(.net)和精心设计的语法(C#)是天堂比较,例如vb6。这并不是没有理由说明#/ $
C#的命名约定(看看fxcop)不再包含匈牙利符号。


应该使用哪些命名约定确保程序员不会被欺骗,而不是实际发生的事情。

UpdateEmailAddress()最后删除它

QueryEmailAddress()对它进行修改。

停止()不停止(也许我应该改变我对此的期望

一,多年来看来太多了't)

etcetc


至于更改参数的示例:任何返回多个

值的函数将它们放入一些

集合中并没有多大意义。来自基类:( threadpool)


public static void GetAvailableThreads(

out int completionPortThreads

);


这个函数声明告诉我所有我需要知道的事情(无效,2 * out args)。

这两件事它没有告诉我是否在调用后可以将这些超出的参数设为空,并且可能会引发异常。其中我真的想要知道

。您当前的命名约定提案也不会在没有进一步扩展的情况下解决




我的2美分:)


Edwin Kusters


" Ron Bullman" < RO ********* @ mail.com>在消息中写道

新闻:OW ************** @ TK2MSFTNGP11.phx.gbl ...
Gotta be fun to watch this app after it reaches version 3.2 and see how many
standard names actually still match with what they do.

Over standardisation of naming conventions lead imho to more problems then
they solve.
You are already up to 16 names that involve a combination of just 3
criteria. If a method is defined
as void it does not return a value. If an argument is ref it expects a value
and will change it. if an argument is out is may get a value set. Use common
sense names for your methods that people can understand. And last but not
least use that lovely /// syntax to write readible comments about what the
thing _actually_ does.

Strong types (.net) and a well designed grammar (C#) are a heaven compared
to for instance vb6. It''s not without a reason that naming conventions for
C# (have a look at fxcop) no longer includes hungarian notation.

What naming conventions should do is make sure that coders aren''t tricked
into expecting something else than what actually happens.
UpdateEmailAddress() ending up deleting it
QueryEmailAddress() making modifictions to it.
Stop() not stopping (erm perhaps I should change my expectations about this
one, seen too many over the years that don''t)
etcetc

As for an example of changed arguments: any function that returns multiple
values where it really doesn''t make much sense to put them in some
collection. From the base classes: (threadpool)

public static void GetAvailableThreads(
out int workerThreads,
out int completionPortThreads
);

This function declaration tells me all I need to know (void, 2* out args).
The two things it does not tell me is if those out params may be null after
the call and which exceptions might be raised. Which I actually would like
to know. Your current naming convention proposal also won''t resolve that
without further extending it.

My 2 cents :)

Edwin Kusters

"Ron Bullman" <ro*********@mail.com> wrote in message
news:OW**************@TK2MSFTNGP11.phx.gbl...

以下各种方法我都无法找到
的正确(通常同意)名称。

类(静态)方法:
c1 )返回值,不修改其参数的内容并且
不会改变类的状态(类访问器?)
c2)返回值,不修改它的参数的内容和
改变了类的状态(类mutator?)
c3)返回值,修改其参数的内容并且
不会改变类的状态(类?)
c4)返回值,修改其参数的内容和
改变类的状态(类mutator?)
c5)doesn'不返回值,不修改其参数的内容
并且不会改变类的状态(没用?)
c6)没有返回值,没有不要修改它的内容s参数
并更改类的状态(类mutator?)
c7)没有返回值,修改其参数的内容并且
不会'' t改变类的状态(类?)
c8)没有返回值,修改其参数的内容和
改变类的状态(类mutator?)
实例方法:
i1)返回值,不修改其参数的内容并且
不会改变实例的状态(实例访问器?)
i2 )返回值,不修改其参数的内容和
更改实例的状态(实例mutator?)
i3)返回值,修改其参数的内容并且
不会改变实例的状态(实例?)i4)返回值,修改其参数的内容并改变实例的状态(实例mutator? )
i5)没有返回值,没有修改其参数的内容
并且没有不改变实例的状态(无用?)i6)没有返回值,不修改其参数
的内容并更改实例的状态(实例) mutator?)
i7)没有返回值,修改其参数的内容并且
不会改变实例的状态(实例?)
i8)不'返回值,修改其参数的内容并改变实例的状态(实例mutator?)

任何想法在哪里找到C#中定义的术语(和/或.NET)
上下文?很高兴知道从业者使用了哪种非官方名称?

在任何情况下都可以使用这样的方法来修改内容它的论点(c3,c4,c7,c8,i3,i4,i7,i8)?

Ron
Hi,

I haven''t been able to find proper (commonly agreed) names for the following kinds of methods.

Class (static) methods:
c1) returns value, doesn''t modify the content of its argument(s) and
doesn''t change the state of class (class accessor?)
c2) returns value, doesn''t modify the content of its argument(s) and
changes the state of class (class mutator?)
c3) returns value, modifies the content of its argument(s) and
doesn''t change the state of class (class ?)
c4) returns value, modifies the content of its argument(s) and
changes the state of class (class mutator?)
c5) doesn''t return value, doesn''t modify the content of its argument(s) and doesn''t change the state of class (useless?)
c6) doesn''t return value, doesn''t modify the content of its argument(s) and changes the state of class (class mutator?)
c7) doesn''t return value, modifies the content of its argument(s) and
doesn''t change the state of class (class ?)
c8) doesn''t return value, modifies the content of its argument(s) and
changes the state of class (class mutator?)
Instance methods:
i1) returns value, doesn''t modify the content of its argument(s) and
doesn''t change the state of instance (instance accessor?)
i2) returns value, doesn''t modify the content of its argument(s) and
changes the state of instance (instance mutator?)
i3) returns value, modifies the content of its argument(s) and
doesn''t change the state of instance (instance ?)
i4) returns value, modifies the content of its argument(s) and
changes the state of instance (instance mutator?)
i5) doesn''t return value, doesn''t modify the content of its argument(s) and doesn''t change the state of instance (useless?)
i6) doesn''t return value, doesn''t modify the content of its argument(s) and changes the state of instance (instance mutator?)
i7) doesn''t return value, modifies the content of its argument(s) and
doesn''t change the state of instance (instance ?)
i8) doesn''t return value, modifies the content of its argument(s) and
changes the state of instance (instance mutator?)

Any ideas where to find such terminology defined in C# (and/ or .NET)
context? It would be good to know also what kind of unofficial names are
used by practitioners?

Also in what kind of situations it is acceptable to use such methods which
modifies the content of its argument(s) (c3, c4, c7, c8, i3, i4, i7, i8)?
Ron



这篇关于C#术语问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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