I am not saying that generics is bad, but I am questioning whether generics 
is necessary.


On Tuesday, June 21, 2016 at 3:45:08 PM UTC+7, andrew...@gmail.com wrote:

> >> I was one of the generics supporters for Go in this forum, but now I am 
> not so sure.
>
> But why?
> Generic types is the same types as and the regular types.
> Difference only in that the regular types does not have a parameters but 
> generic types are always have at least one parameter.
> This is why they are called generic (universal) types.
> The same as you don't worry about that the function can have a parameters 
> why you should worry about that the type can have a parameters?
> When for types allowed to have parameters then this get a some benefits:
> 1. Generice types can be "configured" by some requirements (by their 
> parameters)
> 2. Generice types can have a restrictions (eg. each parameter can have its 
> own upper type bounds)
> 3. Generic types are universal types
>
> Eg. Trivial example
>
> type KeyValuePair<K, V> struct {
>   key K
>   val V
> }
>
> You can use this type everywhere since it is universal type.
>
> Below is not the same type (because in generic type system K != V, but 
> here interface{} == interface{}):
>
> type KeyValuePair struct {
>   key interface{}
>   val interface{}
> }
>
> Because power of the generic types in that the they are variative:
> - Covariant
> - Contrvariant
> - Invariant
>
> And they, of course, can have a parameters.
>

-- 
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