3 ms·
Yes, but now you no longer need to change the function declaration and all callsites (major version change) to support new types (if they're slices or not), jus
by cjslep 7y ago
Yes, but now you no longer need to change the function declaration and all callsites (major version change) to support new types (if they're slices or not), just need to implement more reflection or typecasting cases within the function (minor version change).
- tsimionescu 7y agoCounterpoint: if you modify the call site to pass in a new value, you don't know whether the function will accept it or not, since you've opted out of any compiler verification.
- cjslep 7y agoThat's a very weak argument since you're already opting out of every other kind of compiler check by using `interface{}` as an element type to begin with. Yet another reason to just use `interface{}`: if the caller already has a value of type `[]Concrete` then they can just pass it in directly; otherwise the caller will need to allocate and copy the value's elements into a new value of `[]interface{}` type since the `[]Concrete` is not castable: https://play.golang.org/p/whh1mAAlN-N https://play.golang.org/p/whh1mAAlN-N
- tsimionescu 7y agoMy point was that it is a bad idea to write functions that take an interface{} and try to reflect on it, since you are putting out of all compiler checks. You also get a much, much slower function.