8 ms·
If code generation is used to make up for something missing in a language (be it generics, metaprogramming etc.) then that's a pretty clear sign something is wr
by alkonaut 11y ago
If code generation is used to make up for something missing in a language (be it generics, metaprogramming etc.) then that's a pretty clear sign something is wrong.
It's definitely acceptable to use a workaround for a missing feature once or twice in a language, because no language is perfect, and no language benefits from being burdened with all features imaginable.
But if a workaround becomes part of the day-to-day workflow, then you are likely using the wrong language.
Examples could be: using (textual) code generation for generics, or using type annotations throughout a dynamic language project.
- thegenius2000 11y agoWell put. Though I would add that though generics are convenient, they are not as needed nearly often enough to be a crucial missing feature in a language. Yes, it's uncanny to copy here and there, and certainly, the Go team should try and resolve this. But from where I'm standing this (i.e. generics) is one of the very few fair criticisms of Go which can be leveled from the Java, C++ or C# communities.
- Arzh 11y agoCode generation is not about a deficiency in the language, C++ has templating but I will often use code generation since you only need to run that once and templating bloats the compile time for ever.
- tacos 11y agoJunior programmer alert.
- nanny 11y ago>I will often use code generation since you only need to run that once and templating bloats the compile time for ever. Don't you need to compile the generated code?
- prodigal_erik 11y agoFor reproducibility you have to regenerate, write, read, and parse it, which I can't imagine being faster than instantiating a template in memory.
- Arzh 11y agoYes of course, but compiling the code is faster than generating the code and then compiling it. Templates are much slower than just compiling code straight.
- tacos 11y agoWith the exception of pathological metaprogramming examples -- and even those have largely been fixed -- there's no way you could even measure this, let alone justify such a strong, broad opinion. You're using incomplete information to justify sloppy engineering and promoting it to others.
- Arzh 11y agoIt's compile times, those are very easily tested and measured.
- tacos 11y agoTemplatizing/de-templatizing enough code to see a difference would be a significant effort on any non-trivial code base. But I'll spare you the trouble: instantiating a template is less work than parsing a duplicated file. Some of the early C++ compilers had problems but it hasn't been an issue in 20+ years. If you look at both the G++ and Clang test suites you'll see they verify performance, memory usage and correctness with complicated templates by doing basically this exercise for you.
- Arzh 11y agook, thank
- tptacek 11y agoEveryone agrees something is wrong, even the Go team. The debate is whether it's meaningfully wrong, or just "someone's wrong on the Internet" wrong --- because the cost of righting this wrong will be high.