News for hackers. Stuff that matters.
Re:How to Use Go Interfaces by stubish on Monday March 19, 2018 @10:05PM (#16625411)
This. So many packages are a pain to test, because only a concrete implementation is provided. If an interface was used, consumers can swap it out for a mock implementation. It is an almost endemic problem, but the article is criticizing the only available solution (apart from forking).

I am utterly sick of writing fragile scaffolding to deal with these dependencies, to the point I wish that Go provided an implicit interface for every declared type. Testing would be so much easier if I could pass in a MockFoo instead of a Foo, provided MockFoo satisfied the implicit interface.

Re:How to Use Go Interfaces by sythe2o0 on Monday March 19, 2018 @10:34PM (#16625549)
The article, from how I read it, is not suggesting single-implementation interfaces are the problem but instead where those interfaces are stored. The package accepting the interface should define the interface it needs (and perhaps that package defines the mock implementation), and the implementation should exist somewhere else.
Re:How to Use Go Interfaces by ghthor on Tuesday March 20, 2018 @12:35AM (#16626090)
I've programmed in both ways and they each have there place. But in general this is the right way, you shouldn't export interfaces, you should export concrete types and then use the documentation and tests to example what types of interfaces the types can cover.
Re:How to Use Go Interfaces by seanmcdirmid on Monday March 19, 2018 @10:49PM (#16625630)
TypeScript, having a purely structural type system, means any class has an interface. Unfortunately, if the class has any private or protected members, its interface becomes unimplementable.
Re:How to Use Go Interfaces by dahauns on Tuesday March 20, 2018 @06:58AM (#16627414)
Yeah, tricky one, that.

At least you have the workaround

    type PublicPart<T> = {[K in keyof T]: T[K]}; //keyof only sees public properties