News for hackers. Stuff that matters.
Re:Interfaces in Go make it hard to navigate code by nknighthb on Monday May 27, 2013 @06:21AM (#5774121)
I find the author's particular problem utterly baffling from either direction. When presented with io.Reader's specification:

    type Reader interface {
        Read(p []byte) (n int, err error)
    }
It should be obvious to any modestly experienced developer that an ordinary file object is likely to satisfy the requirement of having a common Read method.

This seems like a basic failure to understand what a Go interface is, nevermind any understanding of the standard library.

Re:Interfaces in Go make it hard to navigate code by garethadams on Monday May 27, 2013 @06:56AM (#5774179)
I'm not a Go programmer, but this seems like implicit interfaces could bite you in the ass pretty easily.

For example if I have a Book class that implements a Read method (to mark the book as having been read, for example) then have I just created something which implements io.Reader?

Re:Interfaces in Go make it hard to navigate code by mseepgood on Monday May 27, 2013 @07:11AM (#5774208)
The signature must match as well, not only the name. And even if it matched by coincidence, which is rare enough, in order to mix them up, you would have to be a programmer without any clue what he's programming, randomly combining objects and calling methods without knowing what they're supposed to do.
Re:Interfaces in Go make it hard to navigate code by pjmlp on Monday May 27, 2013 @07:23AM (#5774232)
You just described how off-shoring projects work.
Re:Interfaces in Go make it hard to navigate code by dsymonds on Monday May 27, 2013 @07:05AM (#5774192)
Only if you had a method with that exact signature: taking a []byte argument and returning an int and an error. You'd have to stretch to have that happen by chance.
Re:Interfaces in Go make it hard to navigate code by garethadams on Monday May 27, 2013 @09:44AM (#5774605)
Ok, I did think that would be part of it but the only reference I could find in the documentation was at http://golang.org/doc/faq#overloading which suggested that names are the only thing considered. (The other document I looked at before was http://golang.org/doc/effective_go.html which didn't help)

Fair enough, I did say I was only speculating and I've learned something.

Re:Interfaces in Go make it hard to navigate code by nknighthb on Monday May 27, 2013 @07:20AM (#5774225)
Aside from the accurate response that the signature needs to match, you must understand that Go's type system is deliberately a meld of a very strict type system, and tools that allow you to beat it into a form of duck typing.

It's trying to merge the best parts of two very different worlds. A modest loss of safety is therefore tolerated.

Re:Interfaces in Go make it hard to navigate code by NateDad on Monday May 27, 2013 @07:32AM (#5774253)
Honestly, it's only a loss of safety if you randomly throw types you don't understand into functions you don't understand. And actually... most of the time this will do exactly what you want it to do, especially if you're talking about io.Writer and io.Reader.
Re:Interfaces in Go make it hard to navigate code by tjgq on Monday May 27, 2013 @07:07AM (#5774198)
Only if your Book.Read method has the same signature as Reader.Read (i.e., not just the same name).