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

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



For reproducibility you have to regenerate, write, read, and parse it, which I can't imagine being faster than instantiating a template in memory.


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


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


It's compile times, those are very easily tested and measured.


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


ok, thank




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

Search: