Tuesday, April 6, 2010

C++ sucks part two

You like speed? C++ will not get any faster

Because C++ support for multi-threading is lackluster. You've pretty much got to roll your own carefully constructed tools to avoid even the most common mistakes multi-threading can introduce.

"What about C++0x?" I hear you say. Screw that! Sure a lot of the stuff being proposed is a huge improvement. But it's been sitting around since 98. When am I going to see this in a compiler? When can I use it? I'm slowly dying here as processors get more and more cores.

To write a program in C++ today is to write code that will never run faster. Or will probably crash trying.

You like speed? C++ build times will feel like riding the bus

Builds are sooo slow. While trivial programs can build from scratch in seconds. Typical programs can take minutes to build from scratch. Complex programs can take so long to build it's usually farmed off to servers to do a 'nightly build'.

Let's do some math. Assume a program takes 2 minutes to build and maybe due to crappy makefile handling the programmer does 10 clean rebuilds a day (on average). If programmer is paid $40 an hour then he's paid about $300 a year just to run "make".

You like clean code? Good luck because header files suck

Why in C++ do we have to define all our class functions twice? Because if we try and inline them we just make the builds take forever. Every change to a header file can trigger scores of files to rebuild. If you've got a key file like a render it can chain hundreds of files to rebuild just from adding a comment.

So we carefully construct our header files. Fill them with forward declarations and carefully define our class interfaces in the hope we wont ever have to touch the header file again.

But of course interfaces change all the time. We're constantly adjusting things and kicking off painfully slow builds. Or in a rush to get things working including other header files only to chain up even more slow builds in the future.

But frankly we don't even want header files. A computer could figure out the interfaces for a class. But why doesn't the compiler do this for us in C++? It's just a dumb language that wants you to hand hold it through the build process.