C#4.0的新“命名参数”功能不应该被称为“命名参数”吗?

时间:2021-12-05 16:40:58

I suppose there could be historical reasons for this naming and that other languages have similar feature, but it also seems to me that parameters always had a name in C#. Arguments are the unnamed ones. Or is there a particular reason why this terminology was chosen?

我想这个命名可能有历史原因,其他语言也有相似的功能,但在我看来,参数总是在C#中有一个名字。争论是未命名的。或者是否有一个特殊原因选择这个术语?

4 个解决方案

#1


6  

Yes, you're absolutely right (to my mind, anyway). Ironically, although I'm usually picky about these terms, I still use "parameter passing" when I should probably talk about "argument passing". I suppose one could argue that prior to C# 4.0, if you're calling a method you don't care about the parameter names, whereas the names become part of the significant metadata when you can specify them on the arguments as well.

是的,你是完全正确的(无论如何,在我看来)。具有讽刺意味的是,虽然我对这些术语通常很挑剔,但在我应该谈论“论证传递”时,我仍然使用“参数传递”。我想有人可能会争辩说,在C#4.0之前,如果你正在调用一个方法而不关心参数名,那么当你可以在参数上指定它们时,名称也会成为重要元数据的一部分。

I agree that it makes a difference, and that terminology is important.

我同意它有所作为,这个术语很重要。

"Optional parameters" is definitely okay though - that's adding metadata to the parameter when you couldn't do so before :) (Having said that, it's not going to be optional in terms of the generated IL...)

“可选参数”肯定是可以的 - 当你在之前不能这样做时,它会在参数中添加元数据:)(尽管如此,就生成的IL而言,它不会是可选的......)

Would you like me to ask the team for their feedback?

您是否希望我向团队询问他们的反馈?

#2


11  

Oh, you wanted arguments! Sorry, this is parameters - arguments are two doors down the hall on the left.

哦,你想要争论!对不起,这是参数 - 参数是左边大厅的两个门。

#3


3  

I don't think so. The names are quite definitely the names of parameters, as they are defined and given a specific meaning in the method definition, where they are properly called the parameters to the method. At the call site, arguments can now be tagged with the name of the parameter that they supply a value for.

我不这么认为。这些名称绝对是参数的名称,因为它们是在方法定义中定义并赋予特定含义的,它们被恰当地称为方法的参数。在调用站点,现在可以使用为其提供值的参数名称标记参数。

The new term refers to the perspective of the method caller - which is logical because that's where the feature applies. Previously, callers only had to think of parameters as being "positioned parameters". Now they can optionally treat them as "named parameters" - hence the name.

新术语指的是方法调用者的视角 - 这是合乎逻辑的,因为这是特征适用的地方。以前,调用者只需将参数视为“定位参数”。现在,他们可以选择将它们视为“命名参数” - 因此得名。

#4


0  

I dont know if its worth adding it now, but MS calls it named arguments anyway. See named and optional arguments

我不知道它现在是否值得添加它,但MS无论如何称它为命名参数。请参阅命名和可选参数

#1


6  

Yes, you're absolutely right (to my mind, anyway). Ironically, although I'm usually picky about these terms, I still use "parameter passing" when I should probably talk about "argument passing". I suppose one could argue that prior to C# 4.0, if you're calling a method you don't care about the parameter names, whereas the names become part of the significant metadata when you can specify them on the arguments as well.

是的,你是完全正确的(无论如何,在我看来)。具有讽刺意味的是,虽然我对这些术语通常很挑剔,但在我应该谈论“论证传递”时,我仍然使用“参数传递”。我想有人可能会争辩说,在C#4.0之前,如果你正在调用一个方法而不关心参数名,那么当你可以在参数上指定它们时,名称也会成为重要元数据的一部分。

I agree that it makes a difference, and that terminology is important.

我同意它有所作为,这个术语很重要。

"Optional parameters" is definitely okay though - that's adding metadata to the parameter when you couldn't do so before :) (Having said that, it's not going to be optional in terms of the generated IL...)

“可选参数”肯定是可以的 - 当你在之前不能这样做时,它会在参数中添加元数据:)(尽管如此,就生成的IL而言,它不会是可选的......)

Would you like me to ask the team for their feedback?

您是否希望我向团队询问他们的反馈?

#2


11  

Oh, you wanted arguments! Sorry, this is parameters - arguments are two doors down the hall on the left.

哦,你想要争论!对不起,这是参数 - 参数是左边大厅的两个门。

#3


3  

I don't think so. The names are quite definitely the names of parameters, as they are defined and given a specific meaning in the method definition, where they are properly called the parameters to the method. At the call site, arguments can now be tagged with the name of the parameter that they supply a value for.

我不这么认为。这些名称绝对是参数的名称,因为它们是在方法定义中定义并赋予特定含义的,它们被恰当地称为方法的参数。在调用站点,现在可以使用为其提供值的参数名称标记参数。

The new term refers to the perspective of the method caller - which is logical because that's where the feature applies. Previously, callers only had to think of parameters as being "positioned parameters". Now they can optionally treat them as "named parameters" - hence the name.

新术语指的是方法调用者的视角 - 这是合乎逻辑的,因为这是特征适用的地方。以前,调用者只需将参数视为“定位参数”。现在,他们可以选择将它们视为“命名参数” - 因此得名。

#4


0  

I dont know if its worth adding it now, but MS calls it named arguments anyway. See named and optional arguments

我不知道它现在是否值得添加它,但MS无论如何称它为命名参数。请参阅命名和可选参数