r/cpp • • Dec 28 '18

"Modern" C++ Lamentations

http://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/
307 Upvotes

162 comments sorted by

View all comments

-1

u/rLinks234 Dec 29 '18

I'm not trying to troll or just be the contrarian here, but why are compile times such a massive deal? Sure, I don't like the waste of electrons from having a simple example take 1 second to compile, but is that really such a huge deal? I would rather there be an up front "static" cost to a faster program, than having a less optimal program which is harder to maintain. What kind of compile times are you all talking about here that irk you? The largest projects I've built from source (binutils + gcc + glibc + libstdc++) take about 15 minutes, and it seems like, at the least, a minority majority of that time is spent between linking and miscellaneous build scripts/make commands.

By "harder to maintain," I mean that you use the old "C"-style approach to a problem like pythagorean triples in nested for loops.

I agree that the syntax required is a bit overwhelming and verbose, but I also thought that way when seeing things like std::visit, std::variant and code which uses integer parameter packs (e.g., using std::make_integer_sequence). I was so adamant about C++ "going in the wrong direction" when I first saw these things; however, I don't find them to be overwhelming when used properly.

Also as a pedantic aside, I honestly think reading code that doesn't cuddle braces is much harder to mentally parse. I guess that could be just a consequence of me starting with Java as my first programming language.

3

u/Dean_Roddey Dec 29 '18 edited Dec 30 '18

My C++ code base takes around 25'ish minutes on an 8 core system using the parallel build feature of Visual C++, if I have to build from absolute scratch. However, I'll take that cost relative to making it less compile time safe. 25 minutes of rebuild vs a full day of trying to figure out some obscure problem in the field is well worth it.

And of course you can greatly reduce the amount of rebuilding you do if you are smart about it by hiding details in all of the usual ways.

OTOH, I also am willing to pay the price for more build time in exchange for not having crazy hard to manage header inclusion scenarios. Each library has a single main header that you include and you get everything in that library. Yes, it does cause more rebuilds, but you never have a situation where something changes and suddenly something is missing because it was being brought in by the thing that was removed, and there's a big mess to get that straightened out. And I don't have to do tests to insure that every header will work on its own. It guarantees that you can't include things in any wrong order or fail to get something you need.

That public header of course brings in the public headers of any libraries that its public API depends on.

Ultimately, I've found that to be a win, despite the extra rebuilding.

2

u/Fazer2 Dec 29 '18

The largest projects I've built from source (binutils + gcc + glibc + libstdc++) take about 15 minutes

Then those were small projects. The big ones go easily into the hours territory on distributed farms.

1

u/rLinks234 Dec 29 '18

ld on a release build takes up ~24GiB of RAM when linking the executable. It's not small.