Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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?


How 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.


> 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.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: