4 ms·
The solution of course is for somebody to build a precompiler that lets people write generics, then compiles down their code into go code -- generating all the
by bane 12y ago
The solution of course is for somebody to build a precompiler that lets people write generics, then compiles down their code into go code -- generating all the necessary type-specific code along the way.
Lots of people don't remember this, but there used to be a whole host of such tools in the early Java days when the language was more terrible than it is now. IIR there's a bunch of similar stuff for C as well.
I guess a modern analog would be something like CoffeeScript which fixes all sorts of issues with Javascript.
- twoodfin 12y agoWe could call it go++! More seriously, this would make sense as a prototyping step (I think the Java equivalent was called Pizza?), but ultimately this would be a fork of the language, with all that implies.
- dvirsky 12y agoThere already exist such tools, and especially now with go-generate in 1.4 it's become easier to do that. But we need deeper integration for them, like gocode completion being able to work on the generic files, linters that can lint a template based source file, etc. If a holistic approach like that would exist I'd personally use a preprocessor.
- scott_s 12y agoThat's identical to what they call the C++ approach, except it's just not part of the actual language. I don't think that's an attractive solution.
- laumars 12y agoThere's already tools in Go for meta-programming. In fact coincidentally I was reading about a few of these tools earlier today [1][2][3] - but personally I don't like that approach. [1] http://www.slideshare.net/wuvist1/metaprogramming-go-with-python http://www.slideshare.net/wuvist1/metaprogramming-go-with-py... [2] https://github.com/pquerna/ffjson https://github.com/pquerna/ffjson [3] http://blog.golang.org/generate http://blog.golang.org/generate