-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Allow optional names in some places #6115
Comments
This proposal hypothesizes a lot of things we are unlikely to do. We don't need the language to help for declaring tuples, as it will be done once in the platform for everyone to use. Any slight savings there will just save me a few keystrokes, and help nobody else. I've already typed more keystrokes here than I would save. I doubt we'll take on any of the other issues this is suggested to "improve". Even if we did, those improvements belong in the original feature. I rarely hear people complain about having to name method parameters that they do not intend to use. |
@gafter Not just tuples, per se, I meant all record types in which member names are not that important, such as tuples. This would be useful in interface implementations and method overrides as well, indicating that parameter is not used throughout the method body (as an alternative to
This would be a great addition to the record type declaration syntax, because they are meant to be concise and expressive. I can imagine this will be useful in pattern record types such as ones that I mentioned in #5718. |
I disagree. It would actually be nice if one could optionally specify the names for the parameters of a callback so that they could be picked up by tooling. This is useful in languages like TypeScript. Names are important. |
You can, by using a custom delegate type. And at least ReSharper does use the parameter name from the delegate type in its autocompletion. |
I don't use ReSharper so I don't take advantage of that, but my point was more that names are a good thing, and your remark about ReSharper speaks to one of the few disadvantages of the Func and Action delegates. I think adopting this proposal would be a bad idea, because it aims to allow less information rich declarations. |
Exactly, when types can be expressing enough, names are just additional noise to the code. Take this for example: abstract sealed class Expr;
sealed class Const(double) : Expr;
sealed class Add(Expr, Expr) : Expr;
sealed class Sub(Expr, Expr) : Expr;
sealed class Mul(Expr, Expr) : Expr;
sealed class Div(Expr, Expr) : Expr;
sealed class Pow(Expr, Expr) : Expr;
sealed class Log(Expr) : Expr;
sealed class Sin(Expr) : Expr;
sealed class Cos(Expr) : Expr; You can see what I mean. |
Sure, in this case names don't buy you much. However, omitting them is inconsistent with other parts of the language, provides less information for tooling, complicates or makes XML comment syntax inapplicable, and only saves you 1-2 characters (2-4 counting whitespace) per line compared to: abstract sealed class Expr;
sealed class Const(double x) : Expr;
sealed class Add(Expr x, Expr y) : Expr;
sealed class Sub(Expr x, Expr y) : Expr;
sealed class Mul(Expr x, Expr y) : Expr;
sealed class Div(Expr x, Expr y) : Expr;
sealed class Pow(Expr x, Expr y) : Expr;
sealed class Log(Expr n) : Expr;
sealed class Sin(Expr n) : Expr;
sealed class Cos(Expr n) : Expr; |
@aluanhaddad Names you have chosen not only don't make any sense but also make it even more confusing. They should be |
Discussion on this matter probably belongs to #6739. Closing accourding to the comment above. |
While C# is fusing records and ADTs together, there is still a need for more concise declarations of "records". Types in in these contexts are expressive enough and there is a chance that one never use them and put them directly in
switch
ormatch
which doesn't rely on arg names. Also they are more useful in #5718 where you are defining pattern classes and maybe you just don't care about member names, because these classes will directly used in deconstruction syntax and will use positional matching. With #6067 in place, it also would make sense to have optional names in overridden and abstract methods. And in delegates likeAction<>
orFunc<>
one simply doesn't care about delegate arg names so having it mandatory seems lame, IMO.This syntax is used in method forwarding (#6081) where we just care about method's signature to specify desired overload and having arg names doesn't make sense at all. It also aids #5058 to be effective in declaring tuple types.
The text was updated successfully, but these errors were encountered: