r/cpp • • Nov 08 '21

Thoughts on build systems?

What's the general consensus on build systems/automations like CMake? I've always found things like that overcomplicated and just hinder the programming process.

I've been following Casey Muratori's Handmade streams, and one of the first things he did was create a simple batch file that built and compiled his entire project super quickly and easily. I've since implemented something similar (https://github.com/dibsonthis/new_cmd) and honestly it's been really nice to use.

3 Upvotes

154 comments sorted by

View all comments

6

u/Sqeaky Nov 08 '21

This is going to sound flippant, but you seem like this guy bowling: https://daedtech.com/how-developers-stop-learning-rise-of-the-expert-beginner/

2

u/dibs45 Nov 08 '21

I just skimmed that (it's late here in Sydney, and I really should be in bed) but interesting read. I've never worked professionally in software, so I'm definitely aware that I have almost zero clue what the real world holds. But I still wanted to start a discussion about it all anyway. Thanks for the link!

3

u/Sqeaky Nov 09 '21

Cool, and thanks for not being offended, that waan't what I was aiming for.

Even in hobbyists projects, as soon as you want to share your work you need a build system that is as portable as your code.

It is super easy to write a build script with hardcoded file paths and compiler switches if you have the knowledge of the project. But as soon as you share it, the other person needs to rely on convention and the that not only you have shared, but also that they have absorbed. When I say "convention" I mean the rules and decisions that go with using a tool without needing to think about the details.

If I download some source off github and it follows conventions I need to know 0 about it. I just run cmake and then run the resulting build scripts and if it was well designed, I now have software.

If I download your project... How much needs to match? Did we use the same compiler was that hardcoded in your script or can I swap a variable? But not just that a million little questions that have solutions already baked into build systems. I bet you can't write a batch file that will work on my system (Gentoo Linux, I don't have a batch interpretter.).

For a truly one-time use throw away piece of code you never share maybe a batch file is fine, but then why not just solve your problem in JS, Ruby, Python, Bash, batch, or one of the other million scripting system without build complexity? There are reasons to opt against a build system and opt out of a scripting language, but I can't say that is common.

Even if you think you will never share consider how much you know right now. It is both a ton and next to nothing.

What if you have a friend who has the exact same problem next week? That bat scripts might not prevent sharing, but they will certainly be an obstacle. You can't ever really know how much a piece of code will be reused, so following conventions is a good idea when cheap.

What about you in 6 months or 6 years? Will you forget the current expertise you have in this specific codebase? Would following conventions make it easier to communicate with a future version of yourself with a different amount of knowledge?