logoalt Hacker News

fasterikyesterday at 10:51 PM2 repliesview on HN

I get by without modules or header files in my C++ projects by using the following guidelines:

- Single translation unit (main.cpp)

- Include all other cpp files in main

- Include files in dependency order (no forward declarations)

- No circular dependencies between files

- Each file has its own namespace (e.g. namespace draw in draw.cpp)

This works well for small to medium sized projects (on the order of 10k lines). I suspect it will scale to 100k-1M line projects as long as there is minimal use of features that kill compile times (e.g. templates).


Replies

zabzonkyesterday at 11:19 PM

This might be OK for someone using your files (a bit like a header-only library) but not so great for team development.

show 1 reply
indilyesterday at 11:10 PM

I believe that's called a unity build. Really nice speedup.

show 1 reply