Skip to content

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

Closed
gbracha opened this issue Jun 13, 2012 · 10 comments
Closed

Revise getter/setter syntax #3602

gbracha opened this issue Jun 13, 2012 · 10 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Milestone

Comments

@gbracha
Copy link
Contributor

gbracha commented Jun 13, 2012

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.

@gbracha
Copy link
Contributor Author

gbracha commented Jun 13, 2012

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

@gbracha
Copy link
Contributor Author

gbracha commented Jun 13, 2012

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.

@gbracha
Copy link
Contributor Author

gbracha commented Jun 13, 2012

Spec'ed in 0.11 draft.


Added Done label.

@gbracha
Copy link
Contributor Author

gbracha commented Jun 13, 2012

Analyzer issue #3607.
VM issue #3608.
dart2js issue #3609.

@DartBot
Copy link

DartBot commented Jun 13, 2012

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.

@gbracha
Copy link
Contributor Author

gbracha commented Jun 13, 2012

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!

@DartBot
Copy link

DartBot commented Jul 10, 2012

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.

@DartBot
Copy link

DartBot commented Jul 20, 2012

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 ?

@peter-ahe-google
Copy link
Contributor

Alas, no rejoice. AFAIK, the new setter syntax was abandoned. So no = in the setter name.

@DartBot
Copy link

DartBot commented Aug 16, 2012

This comment was originally written by [email protected]


then the following paragraph in 3.1:
It is a compile-time error if there is more than one entity with the same
name declared in the same scope, with the exception of the operator-, where
both a unary and a binary version may coexist.

needs to be changed back to include setters and getters among the exceptions, right?

@gbracha gbracha added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Aug 16, 2012
@gbracha gbracha self-assigned this Aug 16, 2012
@gbracha gbracha added this to the M1 milestone Aug 16, 2012
copybara-service bot pushed a commit that referenced this issue Oct 18, 2022
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]>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Projects
None yet
Development

No branches or pull requests

4 participants