News for hackers. Stuff that matters.
Re:Maybe adding generics to Go is about syntax after all by jonathankoren on Tuesday September 04, 2018 @10:45AM (#17909385)
If Go gets generics, maybe they’ll actually add an ‘implements’ keyword for interfaces and no more of this:

  var _ SomeIface = SomeConcrete{}
  var _ AnotherIface = SomeConcrete{}
Just to see if you actually implemented all the signatures on the interface correctly.
Re:Maybe adding generics to Go is about syntax after all by cyphar on Tuesday September 04, 2018 @10:52AM (#17909444)
Actually one of the main benefits of Go over Java is the lack of a requirement for "implements" because otherwise it means that you cannot use a type in a context where the original developer did not intend it to be used (though I imagine you're implying that it would not be required).

However quite a few Go developers now use interfaces with an unexported method specifically to stop users from misusing their types in a context they didn't intend. I guess it's come full circle.

Re:Maybe adding generics to Go is about syntax after all by artursapek on Tuesday September 04, 2018 @12:59PM (#17910599)
> However quite a few Go developers now use interfaces with an unexported method specifically to stop users from misusing their types in a context they didn't intend. I guess it's come full circle.

What a horrible hack. Why bother with that? Either export your interface, your don't.

Re:Maybe adding generics to Go is about syntax after all by cyphar on Tuesday September 04, 2018 @01:05PM (#17910663)
Well -- what if you have multiple implementations of an interface and you want users to be able to choose between them (or rather, you want them to be able to write functions around your interfaces)? I don't really like it much either, but it's a completely valid usecase for unexported methods. In fact I'm pretty sure this was an example from the language developers for why you can have unexported interface methods in Go.
Re:Maybe adding generics to Go is about syntax after all by burntsushi on Tuesday September 04, 2018 @01:50PM (#17911160)
> In fact I'm pretty sure this was an example from the language developers for why you can have unexported interface methods in Go.

Indeed. It's used in the standard library for describing Go's AST if I recall correctly.

Re:Maybe adding generics to Go is about syntax after all by dagss on Tuesday September 04, 2018 @10:57AM (#17909481)
Go has a lot of pain points but the one positive thing it has over other languages is how it handles interfaces.

The whole point is that the caller can make new interfaces to fit existing structs in other libraries.

Re:Maybe adding generics to Go is about syntax after all by jonathankoren on Tuesday September 04, 2018 @12:13PM (#17910088)
Actually, two of the pain points of Go is not knowing exactly what interfaces a class implements, and finding out that you misimplemented an interface but not discover this static analysis until you get a runtime type check failure.

All this pain for what boils down to not having to make a wrapper. Sure wrappers are dumb, but pushing a static analysis out to a run time error dumber, especially since implementing interfaces is a lot more common than wrapping 3rd party structs.

Re:Maybe adding generics to Go is about syntax after all by pjmlp on Tuesday September 04, 2018 @11:43AM (#17909810)
Nothing new, ML derived languages also allow for it.
Re:Maybe adding generics to Go is about syntax after all by k__ on Tuesday September 04, 2018 @11:59AM (#17909964)
TypeScript too.
Re:Maybe adding generics to Go is about syntax after all by stouset on Tuesday September 04, 2018 @05:10PM (#17912834)
Implicit implementation of interfaces is a disjoint concept from allowing third-party users to implement new interfaces on first-party or second-party structs.

The latter is wonderful, and other languages support this without needing to resort to the former.