Hi team,

I wanted to provide some feedback on the syntax used in the generics
proposal.

When I first opened the Go 2 playground, it took me a while to realise that
(type T) was a generic parameter and not a function parameter and that (s
[]T) was a function parameter and not a return parameter):

func Print*(type T)(s []T)* {
    for _, v := range s {
        fmt.Print(v)
    }
}

I think this would start to look more confusing when there are return
values (either single or multiple):

func Something*(type T)(s []T) (T, T)*

I think another character would server to improve the readability of the
Print function in this example and hopefully prevent the time required to
grok a generic function to someone who has not seen one in Go before:

func Print*<type T>(s []T)* {
    for _, v := range s {
        fmt.Print(v)
    }
}

func Print*[type T](s []T)* {
    for _, v := range s {
        fmt.Print(v)
    }
}


Cheers,

Rob

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CA%2Bcy9cUuJqOWWwi4m-MSp6gxKLGC4oFNn6y1zYJgN0Aac31sFg%40mail.gmail.com.

Reply via email to