-
-
Notifications
You must be signed in to change notification settings - Fork 745
[std.range docs] drop and dropOne may not mutate the range #10829
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
Conversation
Thanks for your pull request and interest in making D better, @ntrel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#10829" |
Since |
std/range/package.d
Outdated
Unlike `popFrontN`, the range argument is not passed by `ref`, so | ||
it may not be mutated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also outline the condition that determines when this “may” may apply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want something fairly short and clear, then something like
Unlike $(LREF popFrontN), the range argument is passed by value, not by
$(K_REF), so the range is copied, and it's the copy which has elements
popped off prior to it being returned. Whether the range argument is affected
by drop depends on the copy semantics of the range type.
would probably be better.
IMHO, talking about mutation isn't the right thing to be talking about. So, what the caller needs to know is that when they call I would have to sit down and think about this more to come up with a correct way of stating this which isn't long, but IMHO, talking about mutation is the wrong thing to do, because it's the wrong mindset to have. The correct mindset to have is that when you copy a range, you cannot use it again without assigning it a new value first, and that if you want to use the range after you've made a copy, you need to call |
The point of this documentation change is to communicate to users that they cannot write r.drop(3); ...and then expect The full complexity of range copy semantics should definitely be documented somewhere, but I do not think that the DDoc for |
I'm not arguing for laying out the whole issue here. As I said, I'd need to sit down and think about this more to come up with a concise way to say it. My point is that talking about mutation is talking about the wrong thing (particularly since whether any mutation occurs to the argument is implementation-defined). The documentation should point out that the range is copied rather than passed by But if it is going to talk about mutation, I'd argue that it should say something like that whether the original range is mutated depends on the copy semantics of the range type. Talking about "may mutate" is too vague IMHO. Either way, the key point here is the fact that the range is copied and not passed by |
I've changed it to "the source range may not get popped". I think it's outside the scope of these functions to describe when that is, but if there is a good explanation somewhere we can add a link to it.
Yes, if my change is not approved the docs could just say that instead IMO. |
IMHO, talking about popping or mutation is giving entirely the wrong message. The key thing is that a copy takes place. And if we want to talk about what does or doesn't happen to the range that's passed in, we should be saying that it's implementation-defined, because the copy semantics are implementation-defined. We don't have to go into all of the details about why that is, but saying things like the elements "might not be popped off" or that the range "might not be mutated" is incredibly vague IMHO without actually explaining anything. What folks need to be cognizant of is that a copy is being made rather than the argument being passed by |
Fixes #10828.