Hacker News new | ask | show | jobs
by uluyol 3357 days ago
What functions return interface{}? I rarely see it outside of marshaling/unmarshaling (where I believe it would remain even if the language had real generics) and contexts (which would also use interface{} if there were generics).

Sometimes you want dynamic typing, how else will you pretty print structs? The compiler could generate code but that's a lot of bloat. For context, the point of it is that you don't know what's in it, it's an opaque container for information to be used by middleware. The fact that data might be missing lends itself to easier refactoring later on.

I want generics in go, but I don't find my code using much interface{} at all.

1 comments

It really depends on the type of application you're building, I suppose. I've seen applications littered with empty interfaces, and others with hardly any.