Shouldn't C# 4.0's new “named parameters” feature be called “named arguments”?

跟風遠走 提交于 2019-12-12 13:57:06

问题


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?


回答1:


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.

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

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




回答2:


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




回答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:


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



来源:https://stackoverflow.com/questions/306085/shouldnt-c-sharp-4-0s-new-named-parameters-feature-be-called-named-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!