-
Notifications
You must be signed in to change notification settings - Fork 205
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
Allow constructors with a dotted name to omit the class name #4144
Comments
Seems like duplicate / very similar to #3788. |
Not a duplicate, both try to solve the same "problem" but with different approaches. |
I am thinking whether discussed syntax from #357 (lets say class B3 {
.() {
// code here...
}
} |
I wouldn't really say they use different approaches, they only slightly differ in their syntax. const(this.x);
const .new(this.x);
const.name(this.x);
const .name(this.x);
new(this.x);
.new(this.x);
new.name(this.x);
.name(this.x);
factory.new(int x);
factory .new(int x);
factory.name(int x);
factory .name(int x);
const factory(int x);
const factory .new(int x);
const factory.name(int x);
const factory .name(int x); I would be happy with either syntax, as long as i don't have to constantly write the class name.
I'm not sure about that, imo it is a bit too short and difficult to spot. I don't find the benefit of using |
@hydro63 wrote:
It is true that these two proposals have very similar outcomes in many situations. The main difference is that the proposal in this issue is an extremely simple change: Just allow the class name to be omitted from constructor declarations with a two-part name. #3788 is more like a complete reconstruction of the constructor declaration syntax. #3788 does allow for an even more concise form in some cases (like So you might say that #3788 is the highly optimized version, and this proposal is the easy way to get to very nearly the same level of conciseness. It could be argued that both of these proposals fail to provide a clear signal saying "this is a constructor". For example, neither However, both proposals could rely on the This could be taken as an argument in favor of making the In contrast, it could be claimed that All in all, I do think this proposal has some useful properties, in spite of the fact that #3788 is more concise. |
For brevity, we could allow constructor declarations whose name has two parts separated by a period (as in
C.named
) to omit the first part, that is, the class name.For example:
This allows for slightly more concise constructor declarations, especially when the class name is long. Note that we can use this feature also with constructors whose name doesn't (necessarily) have two parts:
Here is a longer example, inspired by #4135:
If we combine this proposal with #4135 then we get the following:
The text was updated successfully, but these errors were encountered: