-
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: semicolon-terminated empty-bodied void virtual methods syntax sugar #8985
Comments
Also for constructors in order to change the access modifier, public class Foo {
private Foo();
} For non-void virtual methods #7737 can provide an even more concise definition. |
I wouldn't mind if |
I'm not so sure, though. Just earlier today, I happened to read this question that Eric Lippert answered. He says:
I have no idea what the implications would be if that were to change, so I'll leave it to someone who's much more familiar with the language internals to answer that. Unless I'm completely off the mark on what you meant. |
I think it doesn't hurt if type inferred protected virtual void F() => default; |
It's curious, this is allowed: private int x;
public void set_X(int value) => this.x = value; but this is not: public virtual void DoOptionalWork(object argument) => ; Not sure if that's any more helpful though. |
Assignment is an expression, an empty statement is not. |
For abstract functions and body-less constructors this is a good idea, I think! (Abstract functions already support this). But for virtual functions, there must always be a body, even if it is empty. Because a virtual function is a valid function in a full instanciable class. It should be clear what happens if this function is invocated, even if it only returns the default value or is empty for Abstract functions however may implement a body. Abstract functions make the class abstract, too (that's why the Also I think it is better to leave the |
Really? A language proposal to save one character? |
In VS2015 this already works for me, just typing I also think, the short semicolon terminated declaration should only be for external and abstract declarations. Indeed when you redefine the accessibility of a constructor - as the word says - you define something, not just declare it. A definition should always have the |
I guess it's not worth it :). |
It's not uncommon to have empty-bodied void virtual methods as a way of providing optional extensibility.
However at the moment they are still required to have an empty body code block:
It's obviously a minor syntax sugar request, but it still has it's small benefits:
Non-void virtual methods are already taken care of with expressions:
The text was updated successfully, but these errors were encountered: