4 ms·
With so many "interface{}"s Go looks more like weakly-typed. "Apply takes a slice of type []T and a function of type func(T) T" And after that golang.org docs
by EugeneOZ 12y ago
With so many "interface{}"s Go looks more like weakly-typed.
"Apply takes a slice of type []T and a function of type func(T) T"
And after that golang.org docs are saying "We don't feel an urgency for them" about generics"...
- falcolas 12y agoLooks are deceiving. `interface{}` != `void *`. The value inside the `interface{}` box is still strongly typed, it's just boxed to make function interfaces simpler (given Go's lack of generics).
- EugeneOZ 12y agoI don't want to say interface{}=void (at least while type assertion isn't used). But please read comment to Apply function [0] and tell me you don't see usual generics record. [0] https://github.com/robpike/filter/blob/master/apply.go#L19 https://github.com/robpike/filter/blob/master/apply.go#L19
- NateDad 12y agoHe does say "don't do this" and that's exactly one of the reasons why... because you lose compile-time type safety (it's still type safe at runtime, though). All the reflection is bound to be slow, as well.
- EugeneOZ 12y agoMy point is not to say "look, this code is dirty". My point is "look, he use generics in comments, in his mind, so it's natural thing and obviously should exist in Go". Only this.