[generics] Some ideas

150 views
Skip to first unread message

Pee Jai

unread,
Jun 16, 2020, 11:12:24 PM6/16/20
to golang-nuts
I read the proposal and am very impressed by it. I have 3 concerns however.

1. `F(type T)(p T) { ... }`

To me, having 2 or 3 sets of parentheses is very weird. All mainstream programming languages have only 1 set of parentheses for the function's arguments. I've never seen 2 before. I know the proposal says the authors of the draft considered other common symbols including colon. I still think `::` seems nicest.

2. Expanding interfaces to include fields

Currently interfaces can dictate methods only. The proposal also adds type lists.
I propose that for the purposes of generics, the interface also defines fields. This has been rejected numerous times for interfaces (as it is now), but for generics, I think it will greatly enhance the power given to developers whilst honouring the intention/spirit of the proposal.

See Typescript for guidance. They have successfully implemented interfaces that can define fields, type lists and method names in their contracts. The team at Microsoft obviously saw a use for it.

3. Compile time.

I started using Go around Go1.3 (the C compiler days). Back then compiling was blink-of-an-eye fast. I used it as a selling point to everyone I met at meetups (there was minimal uptake of Go back then so it was meetups for other languages). Now the compiler is fast but for moderate size projects, it's no longer blink-of-an-eye fast. I don't bother hyping this feature any more.

Obviously based on how generics is implemented, the compiler will again be slower.

I propose a compile flag so that when developing all the generic type checking etc is done at run-time (default behaviour). When ready to build for production, a compile flag can use used to move the type checking to happen at compile time.

Thanks for your time,

- pjebs

Ian Lance Taylor

unread,
Jun 17, 2020, 12:05:21 AM6/17/20
to Pee Jai, golang-nuts
On Tue, Jun 16, 2020 at 8:12 PM Pee Jai <p...@pjebs.com.au> wrote:
>
> I read the proposal and am very impressed by it. I have 3 concerns however.
>
> 1. `F(type T)(p T) { ... }`
>
> To me, having 2 or 3 sets of parentheses is very weird. All mainstream programming languages have only 1 set of parentheses for the function's arguments. I've never seen 2 before. I know the proposal says the authors of the draft considered other common symbols including colon. I still think `::` seems nicest.

Let's get some experience with this syntax before we decide to change it.


> 2. Expanding interfaces to include fields
>
> Currently interfaces can dictate methods only. The proposal also adds type lists.
> I propose that for the purposes of generics, the interface also defines fields. This has been rejected numerous times for interfaces (as it is now), but for generics, I think it will greatly enhance the power given to developers whilst honouring the intention/spirit of the proposal.

Thanks. While it's always interesting to discuss extensions, I don't
see a major need for this one. It seems that it can be done later if
there is a need. I'd prefer to keep this design draft as simple as
possible--and it's already very complicated!


> 3. Compile time.
>
> I started using Go around Go1.3 (the C compiler days). Back then compiling was blink-of-an-eye fast. I used it as a selling point to everyone I met at meetups (there was minimal uptake of Go back then so it was meetups for other languages). Now the compiler is fast but for moderate size projects, it's no longer blink-of-an-eye fast. I don't bother hyping this feature any more.
>
> Obviously based on how generics is implemented, the compiler will again be slower.
>
> I propose a compile flag so that when developing all the generic type checking etc is done at run-time (default behaviour). When ready to build for production, a compile flag can use used to move the type checking to happen at compile time.

Thanks, we have a ways to go before we discuss implementation.
Certainly if we do adopt this design draft we will pay close attention
to compile time.

Ian
Reply all
Reply to author
Forward
0 new messages