Re: [go-nuts] Re: [generics] Print[T Stringer](s []T) vs Print(s []Stringer)

2020-12-27 Thread Arnaud Delobelle
I understand the difference, but that doesn't prevent me from having to choose between the two implementations. To simplify greatly, and as you pointed out in your reply, there is a tension between "simplicity" (non-generic) and "performance" (generic), and that is where I fear the friction wi

Re: [go-nuts] Re: [generics] Print[T Stringer](s []T) vs Print(s []Stringer)

2020-12-27 Thread K. Alex Mills
Since in this case the use of generics doesn't let you do anything new, I would argue that the KISS principle applies and the non-generic version should be preferred. I think a linter can be added to go vet to warn about instances like this one (where the type parameter can be replaced by the type

Re: [go-nuts] Re: [generics] Print[T Stringer](s []T) vs Print(s []Stringer)

2020-12-27 Thread Arnaud Delobelle
In my opinion, the issue is that there are two ways to express (almost) the same thing and that in itself creates friction in the language. There may be a valid reason to choose one version over the other, but every time it will be necessary to review the pros and cons of each alternative. If we

Re: [go-nuts] Re: [generics] Print[T Stringer](s []T) vs Print(s []Stringer)

2020-12-26 Thread K. Alex Mills
While it depends on the final generics implementation, my understanding of how things stand now is that Print would compile down to a separate chunk of binary for each type T that is used. For instance, if you used Print[A] and Print[B] in your code, they would each refer to separate binary impleme

Re: [go-nuts] Re: [generics] Print[T Stringer](s []T) vs Print(s []Stringer)

2020-12-26 Thread Elliot
If we remove slice from OP's example: https://go2goplay.golang.org/p/KSJpRw1Lrmm func Print[T Stringer](s T) { fmt.Print(s.String()) } func Printi(s Stringer) { fmt.Print(s.String()) } Are these two equivalent? When should one be chosen over the other? On Thursday, 24 December 2020 at

Re: [go-nuts] Re: [generics] Print[T Stringer](s []T) vs Print(s []Stringer)

2020-12-23 Thread Henrik Johansson
Why will interfaces be more idiomatic once generics lands? It remains to be seen I guess but I could very well see the other way become the idiom. On Wed, 23 Dec 2020, 21:20 wilk, wrote: > On 23-12-2020, Ian Lance Taylor wrote: > > On Wed, Dec 23, 2020 at 9:54 AM wilk wrote: > >> > >> https://g

[go-nuts] Re: [generics] Print[T Stringer](s []T) vs Print(s []Stringer)

2020-12-23 Thread wilk
On 23-12-2020, Ian Lance Taylor wrote: > On Wed, Dec 23, 2020 at 9:54 AM wilk wrote: >> >> https://go2goplay.golang.org/p/fTW3hJYNgfU >> >> type Stringer interface { >>String() string >> } >> >> Print[T Stringer](s []T) >> >> Print(s []Stringer) >> >> Both forms works. >> How to prevent double