4 ms·
Hopefully generics will help make better libraries for Graphql. Existing libraries resorted to code generation a lot.
by akmittal 5y ago
Hopefully generics will help make better libraries for Graphql. Existing libraries resorted to code generation a lot.
- bogomipz 5y agoInteresting. I'm curious how code generation is/was used to work around the language not having having support for generics? Or was this something specific to Graphql?
- scheme271 5y agoThe kubernetes api (more specifically the k8s apimachinery) code uses codegen in order to create code so that you can convert custom CRDs to go structures rather than working with json. It's one of the more opaque bits of writing go code that works with k8s.
- akmittal 5y agogqlgen is most popular for graphql and uses codegen. It seem to be good but It felt not that easy to use coming from node world(apollo-server). There were bunch of libraries which helped with code generation to work around generics. I don't think it was specific to Graphql. https://github.com/cheekybits/genny https://github.com/cheekybits/genny is one I have seen.
- naikrovek 5y ago> Existing libraries resorted to code generation a lot. guess what generics is in a lot of languages? code generation! the files just aren't saved to disk. IIRC on a podcast I seem to recall hearing that it was implemented this way for Go, at least for the prototype, and it seems likely to me that it is also done this way in production, but not with textual code.
- akmittal 5y agoThats like saying lets just write assembly because eventually code will be converted to assembly. As a developer now we dont have to bother about codegen.
- BobbyJo 5y agoNo exactly. Assembly is more like the generated code than the generator code.
- uluyol 5y agoGo is not quite doing this level of expansion: https://github.com/golang/proposal/blob/master/design/generics-implementation-dictionaries-go1.18.md https://github.com/golang/proposal/blob/master/design/generi... In particular, a single expansion is shared for all pointer types.
- chakkepolja 5y agoI think the word you're looking for is Monomorphization, and AFAIK it's only C++ and Rust that completely monomorphize.
- erik_seaberg 5y ago> aren't saved to disk This is a big win. They can’t get stale, they don’t need review, and you don’t have to remind everyone which files should never be edited.
- gonzo41 5y agoYou don't think graphql is kind of antithetical to the simplicity that go initially was going for?