On 4 February 2015 at 11:11, Egon <
egon...@gmail.com> wrote:
> Also, I was thinking that it might make more sense to write it as Equal
> rather than Diff. It's clearer and avoids the negative form. I would Diff to
> return the difference of the two rather than they are identical... i.e.
> ignoring the error value
>
> if Diff(r1, r2) { print("same contents") }
>
> doesn't really make sense, whereas
>
> if SameContent(r1, r2) { print("same content") }
>
> does...
FWIW I'd probably do something like this. It's a few lines longer
>
> On Wednesday, 4 February 2015 09:37:44 UTC+2, Egon wrote:
>>
>>
http://play.golang.org/p/iuRyQchiK2
>>
>> (Although, I'm sure there's a nicer way to write the handling of error
>> cases...)
>>
>> + Egon
>>
>> On Wednesday, 4 February 2015 05:12:24 UTC+2, Caleb Spare wrote:
>>>
>>> The challenge is to write an elegant implementation of this function:
>>>
>>> // Diff compares the contents of two io.Readers.
>>> // The return value of identical is true if and only if there are no
>>> errors
>>> // in reading r1 and r2 (io.EOF excluded) and r1 and r2 are
>>> // byte-for-byte identical.
>>> func Diff(r1, r2 io.Reader) (identical bool, err error)
>>>
>>> Here's a little harness to test it out:
>>>
>>>
http://play.golang.org/p/d6XdlVQ0FT
>>>
>>> Background: a few weeks ago I wrote this function as part of a very
>>> simple diff package (
https://godoc.org/github.com/cespare/diff). My
>>> implementation is here:
>>>
>>>
https://github.com/cespare/diff/blob/master/diff.go#L16-L48
>>>
>>> I believe my version is correct, but I'm not too happy with it. In
>>> particular, I dislike the usage of io.ReadFull; if one Reader doesn't have a
>>> full buffer's worth of data available, it would be better to read from the
>>> other Reader in the meantime rather than waiting on the first one.
>>>
>>> -Caleb
>