4 ms·
You rarely have `interface{}`, you usually have concrete interfaces. These have the same amount of type safety at compile time for function inputs, there's just
by Manishearth 10y ago
You rarely have `interface{}`, you usually have concrete interfaces. These have the same amount of type safety at compile time for function inputs, there's just an additional runtime cost, which the Go folks are willing to pay.
The fact that interface code often has runtime failures is usually due to a feature Go interfaces get you that many languages with generics don't have in the first place -- the ability to downcast to concrete types.
Now, interfaces sadly do not have the same amount of type safety at compile time for defining new containers and you can't do things like return value polymorphism as well, but it's not that bad.
It requires a different style of programming (the post from rsc linked in the sibling comment is particularly good at illustrating this), but it's not that bad.
I say this as a Rust programmer (also a Go programmer, but primarily a Rust programmer) who absolutely loves generics.
- camus2 10y ago> You rarely have `interface{}`, you usually have concrete interfaces. you're assuming you know the kind of problems I'm trying to solve everyday. You don't. Don't patronize me.
- Manishearth 10y agoI was using a more generic "you", talking about most of the Go programs I've seen. By "you" I meant "Go programmers". Your situation may be different, but I'm describing what most Go programs (that I've seen) look like wrt their use of interface.