Hacker News new | ask | show | jobs
by jstimpfle 1705 days ago
"Header only" might be a bad name, in my perception what it really means is "you can drop the code files into your project; we won't annoy you with our own over-engineered build system".

Slow-compiling APIs can be made in any form, whether "header only" or not. C++ template APIs cannot be compiled separately and can cause long compile times for all transitively dependent translation units.

For example, stb_image.h is a single file that is 1 copy+paste from github away. It compiles quite quickly, and often you will need it alongside only a single .c file in your project, but anyway it's extremely easy to compile it separately. All you have to do is cut+paste the implementation part to a separate .c file.

2 comments

Copy pasting shit in your repo means you are responsible for maintaining that code and need to keep track of upstream manually. Especially in c++ where memory bugs are prevalent, this sounds like a terrible idea.
Templates can be instanted for common types and consumed via binary libraries.

Also modules support templates just fine.

Indeed, header only libs are just doing PHP like programming.