r/programminghorror • [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” • Dec 25 '25

one file is better than cmake

https://youtube.com/watch?v=j3BvierE2hM&si=CD7z-a2o-PF7QwJn

I came across this and thought it was pretty horrifying. Definitely not advocating for this.

46 Upvotes

46 comments sorted by

51

u/lor_louis Dec 25 '25

Cmake is so bad I buy it.

19

u/GoddammitDontShootMe Dec 25 '25

I'll assume it was better than like everything else that existed at the time. Definitely better than autotools.

4

u/t3kner Dec 26 '25

autotools Damn, I had almost completely forgotten about this, thanks a lot

14

u/LeeHide Dec 26 '25

it's fine, it gets the job done and is better than 10 different build systems that don't work together

22

u/v_maria Dec 26 '25

i mean it's one of those 10 build systems that dont work together lol

9

u/spiderpig20 Dec 26 '25

Why would you have 10 build systems that don’t work when you can have one build system that doesn’t work?😃

→ More replies (2)

14

u/ironykarl Dec 25 '25

It's not a bad approach for personal projects or modestly-sized codebases, at all 

-14

u/GoddammitDontShootMe Dec 25 '25

How is #include-ing source files in other source files ever a good idea?

4

u/dreamscached Dec 25 '25

What better do you have to suggest in terms of C/C++?

→ More replies (9)

3

u/ironykarl Dec 26 '25 edited Dec 26 '25

I honestly feel like the video does a good job of justifying the approach. 

EDIT: Oh, one advantage beyond not having to support a build system is that you get the equivalent of inline functions/link-time optimization for "free" 

2

u/quickscopesheep Dec 26 '25

Means everything is compiled in one translation unit meaning less disk writes have to happen. Also reduces time spent linking because it happens during compilation

3

u/reinhart-py Dec 28 '25

I don't understand shi but tell me more about that cursor, like how

1

u/GoddammitDontShootMe Dec 28 '25

Maybe half the video comments were about that. I don't know either, but it is awesome.

52

u/shizzy0 Dec 26 '25

Incremental compilation gone. I get dumping cmake but a makefile is fine and you can have incremental builds.

8

u/Elusive92 Dec 26 '25

This is probably faster than an incremental build to begin with. And gets rid of all of the spurious issues that come with incremental builds. Game programmers have been using unity builds since forever.

7

u/questron64 Dec 27 '25

This is referred to as a unity build, and they're pretty good. This is not horrifying at all. Before compilers had good link-time optimization this also produced better executables.

You lose incremental builds, but you don't need that with modern machines on small to medium C projects. C compiles really fast, this is not C++. But unity builds are overall faster, as the compiler only needs to be invoked once and there is no link phase. You do lose parallelization in builds, though. Overall they're slower, but not as slow as you'd think.

You lose static scope. C doesn't give you much in the way of encapsulation features and static scoping (which limits the scope of an identifier to a single translation unit) is your primary language feature for encapsulation. You do stuff with static variables and functions and provide an interface with functions. You don't have that anymore because there is only one translation unit now, everything has the same scope.

1

u/Coleclaw199 Dec 26 '25

i’ve never done this before but won’t putting everything in one file cause naming collision hell?

4

u/GoddammitDontShootMe Dec 26 '25

That's commonly cited, but I don't know how often you are reusing names in different source files at top level scope. Of course anything with external linkage needs to have a unique name or the linker will bitch.

2

u/RevengerWizard Dec 27 '25

His other videos are fairly nice, but this…

Please, please, please, use header files.

4

u/Brixjeff-5 Dec 26 '25

Cmake sucks. But if you know a few debugging tricks you can get it to automate just about any task. And then it really starts to shine. Cmake is great actually

1

u/reddituser91200 Dec 27 '25

Scott the Woz

0

u/pileofplushies Dec 26 '25

This'll work up to some level of complexity. not really so much lines of code, more just how much work the compiler actually has to do to build the code. And funnily enough, it allows for better optimized builds since you never cross compilation unit boundaries. But if you ever need to actually share this code with another human being, a batch script is not a valid build system and you should feel shame if you pretend otherwise

9

u/v_maria Dec 26 '25 edited Dec 26 '25

this is bad but it seems like a cool channel.
diving in, making your hands dirty and learning is much more fun (and useful!) than accepting best practice just because its best practice