4 ms·
Surely if you use code generation to create an "IntFancyDataStructure" then, once generated, type safety is ensured? There's no type erasure, no interface{} etc
by seertaak 9y ago
Surely if you use code generation to create an "IntFancyDataStructure" then, once generated, type safety is ensured? There's no type erasure, no interface{} etc., in fact from compiler's point of view it's as simple as it gets. Or am I missing something?
- stewbrew 9y agoHow would you define a function that accepts/returns FancyDataStructure of any type or only of a type that has X embedded? BTW type erasure isn't necessarily a bad thing when the compiler can prove the code is correct at compile time.
- seertaak 9y ago> How would you define a function that accepts/returns FancyDataStructure of any type or only of a type that has X embedded? I'm not sure what you mean by this. If you mean that it accepts any type known at compile time, then you use the code generator (we're talking about a function template, after all). If you want this to work with any type known at runtime, then use Go's interface since you need the vtable. > BTW type erasure isn't necessarily a bad thing when the compiler can prove the code is correct at compile time. Sure, though I'm not sure what the performance implications -- and while I can think of some counter-examples were this wouldn't be the case, in most cases the impact would probably negative.