[go-nuts] Define method on scope-local type

2016-08-18 Thread Joshua Liebow-Feeser
Hi All, TL;DR: While you can define types inside of functions (or scopes inside of functions), those types can't have methods on them. This limits the usability of this feature. I propose that we add the ability to define methods on scope-local types. This came up while discussing the limitati

[go-nuts] Define method on scope-local type

2016-08-18 Thread Joshua Liebow-Feeser
Hi All, TL;DR: While you can define types inside of functions (or scopes inside of functions), those types can't have methods on them. This limits the usability of this feature. I propose that we add the ability to define methods on scope-local types. This came up while discussing the limitati

Re: [go-nuts] Define method on scope-local type

2016-08-19 Thread Paul Jolly
I've been following the same Github issue. > ... but the particularly annoying part is having to clutter the global > namespace by adding a global type which implements the interface > As part of an extension to sortGen I've also been th

Re: [go-nuts] Define method on scope-local type

2016-08-19 Thread Joshua Liebow-Feeser
Hey Paul, I think those are interesting ideas, but my concern about scope-local methods extends beyond just the methods of the sort.Interface interface; I was just using that as an example. The same complaint applies for any type used only within a given scope that needs to implement any interf

Re: [go-nuts] Define method on scope-local type

2016-08-19 Thread Paul Jolly
I did indeed mean to reply to all (done that this time)! Sure, I understand that it's "cleaner", but I'm advocating the internal package approach because: - it solves the problem today - it benefits from being able to take advantage of existing compile time optimisations without needing

Re: [go-nuts] Define method on scope-local type

2016-08-19 Thread Joshua Liebow-Feeser
Does it really make sense to create an internal package just to define a single small, one-off type? Also, I don't imagine that any of the optimizations would need to be reconsidered; the scope is strictly a subset of the scope at which the optimizations operated before, so there shouldn't be any *

Re: [go-nuts] Define method on scope-local type

2016-08-19 Thread 'Axel Wagner' via golang-nuts
It would probably be useful, but to be fair, I rarely had this problem aside from sort. I think this mechanism is better suited for the occasional edge-case (as it doesn't require a language change): https://github.com/golang/go/issues/4146 On Fri, Aug 19, 2016 at 8:49 PM, Joshua Liebow-Feeser wr

Re: [go-nuts] Define method on scope-local type

2016-08-20 Thread Paul Jolly
> > Does it really make sense to create an internal package just to define a > single small, one-off type? > It does "feel" like an overkill, yes. But it's one means of solving the problem *today*. Just to be clear; in offering this as a solution, I'm not saying that I'm 100% happy with the curre

Re: [go-nuts] Define method on scope-local type

2016-08-20 Thread 'Axel Wagner' via golang-nuts
You can, of course, create internal packages if you want to, but I'd see that as completely unnecessary. You can just create an unexported type just as well. internal packages should be used sparsely. On Sat, Aug 20, 2016 at 11:34 AM, Paul Jolly wrote: > Does it really make sense to create an in

Re: [go-nuts] Define method on scope-local type

2016-08-20 Thread Paul Jolly
> > You can, of course, create internal packages if you want to, but I'd see > that as completely unnecessary. You can just create an unexported type just > as well. > But declaring an unexported type pollutes the package namespace, and that's what Josh is (understandably) trying to solve for