Skip to content
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

Add null-aware subscript operator ?[] to Language Tour #3657

Closed
mleonhard opened this issue Nov 3, 2021 · 5 comments · Fixed by #3674
Closed

Add null-aware subscript operator ?[] to Language Tour #3657

mleonhard opened this issue Nov 3, 2021 · 5 comments · Fixed by #3674
Labels
a.language Relates to the Dart language tour e0-minutes Can complete in < 60 minutes of normal, not dedicated, work e1-hours Can complete in < 8 hours of normal, not dedicated, work p2-medium Necessary but not urgent concern. Resolve when possible.

Comments

@mleonhard
Copy link

The page https://dart.dev/guides/language/language-tour#other-operators
lists operators (), [], ., and ?.. It is missing ?[]. I wasted many minutes looking for it and finally found it in dart-lang/language#376 . Let's add it to the language tour to save other users' time.

@kwalrath kwalrath transferred this issue from dart-lang/language Nov 3, 2021
@kwalrath kwalrath added e0-minutes Can complete in < 60 minutes of normal, not dedicated, work e1-hours Can complete in < 8 hours of normal, not dedicated, work a.language Relates to the Dart language tour p2-medium Necessary but not urgent concern. Resolve when possible. labels Nov 3, 2021
@mmcdon20
Copy link
Contributor

mmcdon20 commented Nov 3, 2021

I agree that ?[] should be mentioned in the language tour.

I also wish the language tour would mention that async, async*, and sync* keywords can be used with anonymous functions.

@parlough
Copy link
Member

parlough commented Nov 8, 2021

@kwalrath I noticed we currently call the [] operator the "List access" operator here, do we want to name that something more generic like the "subscript operator"? I don't believe the spec has a name for it as technically that is dependent on each individual overriding case, but it seems subscripting is a commonly accepted name and is also what Swift uses.

@kwalrath
Copy link
Contributor

kwalrath commented Nov 9, 2021

I was going to say that we should use the name in the spec, but it seems to studiously avoid naming [] (if it ever did name it). We might just want to call it the [] operator, like the spec does. Edit: I see that it's helpful to have it in the table. I could ask Leaf or Bob about what they'd call it.

Btw, ?[ appears to be in the spec only once, in a table ("Figure 3") in section 17.20/17.21 (p. 148) that lists ways to invoke methods, along with each way's desugared form.

@kwalrath
Copy link
Contributor

@munificent or @leafpetersen, does subscript operator work for you, or do you have another suggestion? You can look at #3674 (an update to https://dart.dev/guides/language/language-tour#other-operators) to see how it'd be used.

@munificent
Copy link
Member

munificent commented Nov 18, 2021

Seems like languages are fairly evenly split between "subscript" and "index":

I personally lean towards "subscript" because "index" is used for other things like numeric loop variables.

So, for completeness, I'd use:

  • [] subscript operator
  • []= subscript setter operator
  • ?[] null-aware subscript operator
  • ?[]= null-aware subscript setter operator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a.language Relates to the Dart language tour e0-minutes Can complete in < 60 minutes of normal, not dedicated, work e1-hours Can complete in < 8 hours of normal, not dedicated, work p2-medium Necessary but not urgent concern. Resolve when possible.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants