Re: [go-nuts] Re: GOTCHA: Just when you think you understand interfaces

2018-02-05 Thread 'Axel Wagner' via golang-nuts
On Mon, Feb 5, 2018 at 1:13 PM, Chris Hopkins wrote: > Well, the first allows one Less per package, the second allows one per > type. > No, the first allows an arbitrary number of Less' per package or type and the second one allows one per type. You can call a function LessByName, LessByID, Less

Re: [go-nuts] Re: GOTCHA: Just when you think you understand interfaces

2018-02-05 Thread Chris Hopkins
Well, the first allows one Less per package, the second allows one per type. Since I tend to have multiple types in a package I find that more readable. Anyway, I finally fixed the problem with mixture of reflect and type assertion val := reflect.ValueOf(b) if val.Kind() == reflect.

Re: [go-nuts] Re: GOTCHA: Just when you think you understand interfaces

2018-02-01 Thread 'Axel Wagner' via golang-nuts
I don't really see the difference in writing func Less(a, b *T) bool and func (a *T) Less(b *T) bool convenience wise - except that the latter requires the name to be exported and doesn't allow using a function literal (so, yeah, the latter actually seems significantly *less* convenient). On Thu,

Re: [go-nuts] Re: GOTCHA: Just when you think you understand interfaces

2018-02-01 Thread Chris Hopkins
No, was hoping to use the interface (It's the only reason I defined it) to test if two items are equal. I guess I could enforce that you have to supply the equals function like the sort interface does. I was just hoping for more. I'll have a rethink next time I have time. Thanks On Thursday, 1

Re: [go-nuts] Re: GOTCHA: Just when you think you understand interfaces

2018-02-01 Thread 'Axel Wagner' via golang-nuts
On Thu, Feb 1, 2018 at 11:52 AM, Chris Hopkins wrote: > Yeah, so having played with this. It seems that this is going to take some > judicious use of reflect if I'm to stand any chance of maintaining a > flexible API, which I really hoped to avoid. > I'm 99% sure that you don't have to use refle

[go-nuts] Re: GOTCHA: Just when you think you understand interfaces

2018-02-01 Thread matthewjuran
For issue tracker reports these questions are asked: What did you do? What did you expect to see? What did you see instead? Please describe your API needs in more detail. Interfaces are useful for API design but it appears we may be misunderstanding what your interface type assertion needs ar

[go-nuts] Re: GOTCHA: Just when you think you understand interfaces

2018-02-01 Thread Chris Hopkins
Yeah, so having played with this. It seems that this is going to take some judicious use of reflect if I'm to stand any chance of maintaining a flexible API, which I really hoped to avoid. I had assumed that the point of interfaces was to avoid this. I guess from a high level I don't see why a s

[go-nuts] Re: GOTCHA: Just when you think you understand interfaces

2018-01-31 Thread 'simon place' via golang-nuts
also notice, if you haven’t encountered it, this makes []interfaces a bit awkward to handle with ellipsis functions... https://play.golang.org/p/JWuc4jt2uSP what i do is this; https://play.golang.org/p/O9Q4K_vXlul but you will need a convert for all combinations of interfaces and ellipsis fu