Hacker News new | past | comments | ask | show | jobs | submit login

I also miss generics in Go. It is especially a pain to implement a nice high performance collections library without them. I have been working on and off on a data-structures library and you have to go through a lot of hoops to make it nicely usable and your still end up with `interface{}` everywhere.[1]

It should be noted that this is not the first attempt by any means. droundy implemented basically this several years ago.[2] The problem is these things are non-standard and I don't feel comfortable using them. I want generics but I want them as part of the language not as some weird third party CGI script. I also want them integrated into the template system. That way I can create type variables which must implement an interface. However, when the code is actually run, it isn't an interface object it is the actual object. Features like that would make them fit much better with the rest of the language.

[1] https://github.com/timtadh/data-structures [2] https://github.com/droundy/gotgo




The key innovation here is that it uses the URL to do the parameterization. That's not what is implemented in your reference [2].

I think this approach is actually quite clever. It's clever because URLs belong to a global namespace. If you have third-party code that is also using an instantiated generic, your code should be compatible with it because you'll be using the same URL. Whereas locally-generated templates are more problematic - compatibility depends on build scripts etc.


I agree this does solve the `go get` problem. However, a better thing would be to improve `go get` and make it use an actual build system. `go generate` is a step in the right direction but they expect you to check the generated sources in. I would prefer a tool chain that allowed your API customers to do code generation from your library. However, these things are more complicated and the Go Author's are probably right to do the simplest thing first.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: