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

LinkedList.forEach allows to modify the list #13571

Open
DartBot opened this issue Sep 25, 2013 · 5 comments
Open

LinkedList.forEach allows to modify the list #13571

DartBot opened this issue Sep 25, 2013 · 5 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-a docs-api docs-articles library-collection type-documentation A request to add or improve documentation

Comments

@DartBot
Copy link

DartBot commented Sep 25, 2013

This issue was originally filed by alexe.kaigorodov@gmail.com


void forEach(void action(E entry))
Call action with each entry in the list.
It's an error if action modify the list.

An error indeed is thrown when action modify the list, but only after the list is actually modified. Usually when an invalid action is attempted, an error is thrown and the action have no consequences. Either implementation should be fixed and react early, or documentation should mention this peculiarity.

@lrhn
Copy link
Member

lrhn commented Sep 25, 2013

We don't plan to intercept all attempts to mutate a list while it's being iterated.

For iterating with an Iterator, it's not possible, because we don't know when iteration is done.
For forEach, it would be possible, but only at the cost of an overhead on every mutating access, even when you are not iterating - something like:
  add(x) {
    if (isIterating) throw error;
    ... actual adding ...
  }

We try to optimize for correct programs, not errors, so it's ok that the erroneous program does something bad before it's clobbered. We throw an error, and it's perfectly reasonable to terminate the program as a result.

So, this boils down to a request for better documentation.

Notice that generally we write "It is an error if ...". That does not mean that doing so will always throw an Error. It likely will, and we try to do so, but it rally just says that "You must not do ...", and if you do, the result is unspecified.


Removed Type-Defect label.
Added Type-Enhancement, Area-Documentation, Triaged labels.

@kwalrath
Copy link
Contributor

We should make the API docs clearer (this problem is in lots of places) and also provide a doc comment guideline to encourage better wording.

@kwalrath
Copy link
Contributor

Added Docs-API, Docs-Articles labels.

@kwalrath
Copy link
Contributor

kwalrath commented Jun 4, 2014

@DartBot DartBot added type-documentation A request to add or improve documentation Priority-Unassigned area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. docs-api docs-articles library-collection labels Jun 4, 2014
@lrhn lrhn removed the core-m label Aug 23, 2017
@bkonyi
Copy link
Contributor

bkonyi commented Jun 22, 2018

It looks like the documentation here still isn't terribly great. @kwalrath is there something better we can change this to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-a docs-api docs-articles library-collection type-documentation A request to add or improve documentation
Projects
None yet
Development

No branches or pull requests

5 participants