On Tue, 2015-03-17 at 15:03 -0700, Uli Kunitz wrote:
> The io.Reader documentation contains following two sentences:
>
> When Read encounters an error or end-of-file condition after successfully
> reading n > 0 bytes, it returns the number of bytes read. It may return the
> (non-nil) error from the same call or return the error (and n == 0) from a
> subsequent call.
>
>
> The third word is encounters.
Yes, sorry. How do you define "encounter"? I would say it's encountering
a state, which is defined in io.EOF as when there is no further input
available.
> The documentation talks then about an instance of the general case, where
> the next call must return EOF. But this is a special case and in the
> general case only one of the following calls must return EOF. The
> documentation only discourages returning 0 bytes without an error with the
> exception of a zero-length buffer, but doesn't outlaw it.
I'm not asking for it to be outlawed.
> In my reading you could even state that returning (0, nil) for all calls
> with a zero length buffer even after encountering EOF and returning n less
> than len(buf) doesn't violate the specification. The type strings.Reader
> does exactly this. Note also that an EOF error doesn't need to be repeated.
After comments on the gerrit CL, I can see why people see this to be the
case, however, I stand by the claim that the wording is unfortunate
(removal of the word "regardless", would fix that). The emphatic nature
of that clause, to my mind, makes the sentence it is in take priority
over the last para of the io.Reader documentation.
> I believe the Reader specification doesn't provide more specificity by
> intention.
I'm not claiming it's not specific enough, but rather that it's too
specific.
> Readers that are concurrently filled while read might not be
> able to fill the buffer completely at some point in time so one cannot
> assume that reading less bytes than the buffer size indicates EOF.
I think this is a different issue.
> I hope I could show that strings.Reader doesn't violate the io.Reader
> specification and while your proposed behaviour is satisfying the
> specification it doesn't forbid other behaviours including strings.Reader.
I agree, when regardless is interpreted to refer only to the previous
clause. In my English, that is not unambiguously possible.
thanks