Skip to main content

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.

Comments

Popular posts from this blog

Setting up Fitnesse on Ubuntu in 7 steps

Some pretty basic steps but just to make sure it's here for everyone to see. Setting up fitnesse and running the jar is easy enough. Just go to http://fitnesse.org/ and get started and do it on your desktop just to see it in action. But for me that wasn't good enough I wanted it to run as service on ubuntu. I stole a few tricks from how ubuntu runs jenkins and setup fitnesse a similar way. 1. Create a user and group for fitnesse (optional) I didn't do this because I wanted tomcat, jenkins and fitnesse all running as the same user. Call it laziness to avoid any permissions classing but it doesn't change the process that you need to create or choose what user you're going to make it run as. Don't make it run as your user or root! 2. Download the jar file and place it in /usr/share/fitnesse Make the folder too of course. It can belong to root as long as the fitnesse user has read access 3. Create the folder to run in at /var/lib/fitnesse Fitnesse user needs...

RestFixture

So most of the tests I'm writing now in Fitnesse are using RestFixture . Being able to do all this black box style testing has helped me get a lot of tests up and running without having to change the existing code base. Now I've taken a step future with my own little fork  so I can use scenarios and build nice BDD style scripts. But first I want to give me own quick guide to using RestFixture Step 1: Installing You can dive straight in by grabbing the latest jar files for RestFixture here  https://github.com/smartrics/RestFixture/downloads If you know what you're doing can get the nodep version to work nicely along side other libraries you may be including in Fitnesse. But I grabbed the 'full' version and unzipped it into a RestFixture folder alongside my FitNesseRoot folder. Step 2: Write your first test I took advantage of the built in Fitnesse api as a basic test and wrote a page called RestFixture with the following contents !define TEST_SYSTEM {slim} !...

Are mocks/fakes reusuable?

Programming 101 states: Don't copy and paste code. If you find yourself doing something repetitive then do it right so you can reuse the same code. Functions, classes and even separate files all serve this end. Now that I'm writing tests all the time I often find myself creating Mocks. Mocks are where you tell code to use a pretend version of some functionality instead of the real one. It could be because the real one does something you don't want in your tests (writes files, reads a database) or it could be that you've got some messy legacy code you can't to pull into your tests (yet). There's other reasons too but you get the idea. So if I make a Mock version of a class it makes sense to try and share that with everyone else that might be trying to test with that same class. Or does it? That assumption has some serious flaws that I'm only now starting to understand. And here's a few: Behaviour you need to test may be completely different to the next gu...