3 ms·
> the ubiquitous `interface{}` pattern Ubiquitous where? It's the equivalent of `Any` in Scala (and other similar strongly typed languages with unified type hi
by darkr 7y ago
> the ubiquitous `interface{}` pattern
Ubiquitous where? It's the equivalent of `Any` in Scala (and other similar strongly typed languages with unified type hierarchy) and should be strongly discouraged in production code.
- ben0x539 7y agoStandard library APIs like context.Context's WithValue/Value, sync's Map/Value/Pool, stuff like the sort or container/heap packages. Some of them are obvious "really wanted generics, but wasn't important enough to get the special built-in treatment" cases, some aren't. Most logging libraries I've seen follow the pattern from fmt.Println etc to accept arbitrary `interface{}` values to be logged instead of actually using some Stringer or Formatter interface in their actual method signatures.
- saturn_vk 7y agoContext's WithValue will be an interface even if go supported generics. It stores anything, not values of a specified type. Same with fmt
- ben0x539 7y agoYeah, that's what I meant with "some aren't", I was mostly listing stuff to support the idea that `interface{}` itself is ubiquitous and not some super-niche edge case that never shows up in real code.