Nice find wrt: mgo. That is a good analogy.

And thanks for your input.  That is a good observation that it could also 
save some internal conversion.

-- Jonathan

On Tuesday, May 2, 2017 at 8:12:39 PM UTC+2, Jonathan Hall wrote:
>
> I have a public API that takes `...interface{}` as an argument.  (For 
> reference: https://godoc.org/github.com/flimzy/kivik#DB.BulkDocs )
>
> I'm considering changing this to instead take `interface{}` as an 
> argument, then using reflection to:
>
>   - Validate that the underlying type is an array
>   - Convert to `[]interface{}` before using it internally
>
> The reason I'm considering the change is that the normal use-case for the 
> function is on an array of specifically-typed documents, and converting to 
> `[]interface{}` before every call is cumbersome, and redundant ~95%+ of the 
> time.
>
> I'm wondering if I might be overlooking any obvious drawbacks to this 
> approach.  Thus far, my hesitation comes from the following facts:
>
> - Using reflection to check that an argument is an array seems sloppy 
> (although I've seen it before). It loses all benefits of compile-time 
> checking
> - Using reflection for the conversion is presumably slower than doing the 
> conversion in the caller.
>
> Are there other pros or cons I'm not considering that I should take into 
> account when deciding how to proceed?
>
> Much thanks,
>
> -- Jonathan
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to