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
bufio: document SplitFunc corner cases #25472
Comments
This issue seems two describe two separate issues: missing doc comments, and a requested change in behavior. Please file those separately: documentation issues tend to be relatively easy (and uncontentious) to fix, whereas changes in behavior may require a more rigorous proposal, especially if they are not compatible with Go 1. |
I have rephrase this issue to documentation, and a separate issue will be created after this is done. |
@robpike, you want to clarify Scanner docs here? |
The docs seem to me to cover the situation well enough but of course one can always explain in more detail. Detailed response:
The docs seem clear to me, unless you're arguing that a nil token is somehow special, which it is not. That could be documented but I don't believe it's necessary. Token values are irrelevant to the scanner, which just passes them on. |
The different behaviors between nil and empty slice is not that obvious since those two are generally interchangeable in golang. The difference should be clearly documented here if it is supported. And also the feature "nil token skips bytes" are not always working as expected. In some case it will terminate the scan if the reader already hits a non-nil error. example. As @bcmills suggested the doc need to be fixed before we can fix the implementation. |
I'm sorry but I still don't understand what you're after. If the reader hits an error, the scan always terminates. The token makes no difference. If you believe otherwise, please explain further. I also disagree with the assertion that nil and empty slice are interchangeable. They're not in general. |
If the reader returns error and split function returns nil token, scan
function skip everything still in the buffer, with certain buffer size. If
you check the example I posted
…On Sun, Jun 10, 2018, 5:55 AM Rob Pike ***@***.***> wrote:
I'm sorry but I still don't understand what you're after. If the reader
hits an error, the scan always terminates. The token makes no difference.
If you believe otherwise, please explain further.
I also disagree with the assertion that nil and empty slice are
interchangeable. They're not in general.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#25472 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AILPap4udjFTPGl-5VqLDrhpfYaekVlMks5t7RcugaJpZM4UGQSD>
.
|
It is special, or more precisely, there is no such thing as a nil token: returning Conversely returning This distinction is undocumented; the docs only make a distinction about the
I agree this is also undocumented / confusing. All we know from the docs is that an error from the |
The docs describe what happens when a I think more clarification about returning |
Change https://golang.org/cl/118695 mentions this issue: |
As you said yourself, it doesn't.
Accurate but incomplete.
I agree. That would be the normal case. I was just pointing out that the This only cover the first point in my previous message. There is also the second point: the condition that terminates the scan is also not documented. |
@pam4 Do you agree with the change I sent in https://golang.org/cl/118695 ? I feel like the condition that terminates the scan is documented at |
Definitely better.
Have you read my first message? Because I don't know how else to say it... The only relevant part of the docs is:
What does it mean to reach the end of the input? For example, suppose
|
Thanks, I added a comment about what happens if the |
Thanks.
I think this sentence is very effective to clarify my first point.
It is correct, but how about something like:
|
Fixes golang#25472 Change-Id: Idb72ed06a3dc43c49ab984a80f8885352b036465 Reviewed-on: https://go-review.googlesource.com/118695 Reviewed-by: Rob Pike <r@golang.org>
I just discovered that I had a misconception about it, which was probably caused by the above sentence. There are exactly 3 ways for the scan to stop. None of them could be really described as "by reaching the end of the input":
I think it is easy to interpret the quoted sentence to mean that you can also stop the scan by just advancing the input to the end. Probably the OP was also confused by this, considering his examples. EDIT: Another observation:
Actually, it doesn't matter if they are empty (as in zero-length) or not. Even though such distinction wouldn't make a difference for most users, I don't see why the docs should be so approximative. |
The current document of
bufio.SplitFunc
does not cover all cases and left few details buried into implementations. Such as:Here I propose few changes to doc, clearly state those behavior. Such as:
The text was updated successfully, but these errors were encountered: