[Proposal] Internal and external method parameter names #658
Replies: 5 comments 3 replies
-
I think the best practise would actually be using document comments and/or good parameter names to begin with....... |
Beta Was this translation helpful? Give feedback.
-
I like the inline syntax better. Attribute syntax was mostly inspired by PowerShell's [Alias] attribute, [DisplayName] in serialization and [Route] attribute in ASP.NET; which exist to provide similar functionality. |
Beta Was this translation helpful? Give feedback.
-
Ideally parameters have really communicative names, not short names, both for consumers and implementation. |
Beta Was this translation helpful? Give feedback.
-
I personally hate the naming conventions with internal and external parameter names in swift. I guess it's all a matter of preference. |
Beta Was this translation helpful? Give feedback.
-
Long time C# enjoyer here. After adding experience with Swift I did find myself missing internal/external parameter names in C#. In the external context of a method call longer parameter names have the ability to make the call of a method read like a sentence which makes the code easier to read and understand. However, in the local context of the method implementation, long parameter names are not adding to the readability of the code unless the method implementation is long, in which case it should be refactored using sub methods anyway. Instead, for a nice short implementation, long parameter names often make the algorithm harder to read and understand. Therefore I really appreciate to have the opinion to separate the names between call and implementation and hope this will be added to the language. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
(Reposted from the Roslyn repo)
I'm proposing new syntax for C# to allow methods to optionally have internal (scoped) names for parameters that are different to the exposed external names that consumers see.
This is based on my experiences with Swift and Objective-C where parameters have separate "parameter name" and "argument labels" (which better translates to "internal names and external names" in my opinion).
This is most useful if you need to use verbose parameter names for external callers but inside the function scope those long names get tedious, for example:
I advocate using an inline syntax for alternative names, instead of the use of attributes seen in the original Rosyln issue, so this would become:
...The external caller would still specify
fromAccountId:
toAccountId:
andtransactionAmount:
but the author of the function definition would use the more succintfrom
,to
andamount
names.I find Swift and Objective-C's mandatory labels a bad design choice (though Swift allows the use of underscores), but using a triple
Type externalName [internalName]
syntax is succint, easy to read, and doesn't conflict with any existing or proposed syntax constructs I'm aware of.As a bonus, this could be combined with a possible future Record-type syntax, to ensure the public member names and parameter names have the preferred names (mostly thinking of PascalCase vs camelCase):
Becomes:
I'm hesitant to refer to the differing external and internal names as "aliases" because the compiler could actively prevent code in the consumer from using external names internally - or vice-versa: consumers using internal names - I have no strong opinions either way:
(I'm prepared to develop this into a prototype fork of Roslyn, though it would be my first foray into modifying the compiler.)
Another advantage is that it allows the public API surface to be kept constant and so not breaking any existing consumers (especially those using overload selection by argument-name) while changing internal details.
Beta Was this translation helpful? Give feedback.
All reactions