-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Revise getter/setter syntax #3602
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
Comments
The obvious path here is to make the getter parens optional, and likewise the setter = sign. The internal names can be fixed at this time as well. Then fix the libs, then disallow parens on getters and make the = required on setters |
Note that this also eliminates to compile-time error situations: there is no need to check that the formal parameter list of a getter is empty, since there is no parameter list. Also, a setter name can never conflict witha getter or method name, so no need to check for such a conflict either. |
Spec'ed in 0.11 draft. Added Done label. |
This comment was originally written by @mhausner Is get foo { ...statements here...; return value } legal syntax, or did we introduce a situation where the two forms of function blocks (=> and { }) are not interchangeable anymore? I presume the => in get foo=> 42; is a separate token, not part of the getter name, despite the lack of a space in the example above. |
get foo { ...} is perfectly legal. The example using => is just one example. ANd yes, +> is not part of the getter name - the getter name is always an identifier (at least for now - we are likely to view [] as a getter soon - fun details to follow). The 0.11 draft gives the syntax, which is unchanged except that no formal parameter list is allowed in a getter signature, and an extra = sign is introduced before the formal parameter list in a setter signature. Once the change is done, there will be fewer compiler checks and things should be ever so slightly simpler and cleaner. Rejoice! |
This comment was originally written by [email protected] I really don't get this change. Syntactically, it's an ugly change. You already have the "set" keyword to indicate that it's a setter function, so why do you need to have an = as well? I am guessing there is some logical reason for this choice that has something to do with the mirrors system, but why couldn't function mirrors just include some sort of flag on them like isSetter? I'm guessing because then you'd have two functions in the mirror with the same name and only a boolean flag to differentiate them. Still it seems like the syntax is being uglified because there is an issue in implementing mirrors for it and I don't like the resulting compromise. |
This comment was originally written by @tomaszkubacki setter "=" seems really ugly and i agree with #7 smeels like a bad compromise. Can't mirros really workaround this somehow ? |
Alas, no rejoice. AFAIK, the new setter syntax was abandoned. So no = in the setter name. |
This comment was originally written by [email protected] then the following paragraph in 3.1: needs to be changed back to include setters and getters among the exceptions, right? |
Changes: ``` > git log --format="%C(auto) %h %s" 817e61d..b9afe92 https://dart.googlesource.com/pub.git/+/b9afe927 Completely switch from pub.dartlang.org to pub.dev (#3611) https://dart.googlesource.com/pub.git/+/7b65fa73 update docs for running 'pub token' (#3602) https://dart.googlesource.com/pub.git/+/4c9ebd0e Content hashing of archives (#3482) ``` Diff: https://dart.googlesource.com/pub.git/+/817e61d9eb174f77dfd2cb1d1de45826f66ac6bf~..b9afe9270c24d040b8ae465b4b37ba4f7f4b4cc5/ Change-Id: I6d827dd64f822e0194e0e17e95a47f02b744b561 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264701 Commit-Queue: Sigurd Meldgaard <[email protected]> Reviewed-by: Jonas Jensen <[email protected]>
Getter declarations no longer require/allow parentheses: int get foo=> 42;
Setter declarations have an = sign after the identifier: set foo=(int x);
The name of a setter for purposes of reflection and noSuchMethod is id=, whereas the getter is just id. This allows a standard, reliable way to distinguish them by their names just like any other method.
All this needs to get into the spec.
The text was updated successfully, but these errors were encountered: