My First C++0x!


I’d been talking up a storm about c++11 ever since this year’s ./build conference. I saw some folks talk about it and was immediately intrigued. While I love Obj-C I’ve never been much of a C/C++ coder and it always bothered me. Now with the new additions to C++ I feel I have no excuse but to take a deep dive. Hi, I’m Cliff. You’re here because you write some flavor of C code. I’m here solely because I got an adrenaline rush from completing my 1st unit test exercise using “Bandit” with the CMake build system. It’s a rush because I only learned CMake last week, literally between apk compiles. (a few months ago I was barely able to code hello world in regular make.)

What is C++0x?
If you haven’t heard, C++ is not legacy. There have been some enhancements! Back when I was in computer school the big deal was c99, which was a new standard or recommendation. Basically it was what most C++ programmers agreed to as the proper things to include in the language. Ever since then, most people I’ve known have maved on to things like Java, C#, Obj-C, Ruby, Python, etc. C++ was considered “what we used to do before we knew better”. I’ll admit, I let what little knowledge I had about C stagnate. In recent years, however, a bunch of smart people got together and decided to update the ol’ c99 standard and add some new flavor. They call this new flavor C++ 11 but you may see it referred to as c++0x or cx11 or any number of geek shorthand forms.

Why C++0x?
Why would you want to learn C++ or even any new variation of C these days when there are so many other things to do with your life like writing Ruby or Scala, or Clojure? Why would anyone care? Let’s take it back in the mid 2000’s when people used to rave about garbage collection, DSLs, and meta object programming and the like. Back then it was common to hear things like “RAM is cheap”, “CPUs can handle whatever we throw at them”, “Early optimization is evil!” We used to just allocate as needed and throw libraries in without caution. Then something happened. Apple released the iPhone. Mobile computing became important. Suddenly we were right back where we were in the late 90’s when counting bytes was critical. Also people started to realize that extra CPU cycles, and excessively used memory would translate into real $$ in the data centers where racks of servers would run non-stop. Something as simple as unwinding a tail recursive call into a loop could save hundreds if not thousands of dollars. Speed became important again.

As much as I dreaded learning Obj-C and reference counting back then I grew a fond appreciation for what it meant in terms of performance. If you’ve ever tried writing a game on a memory constrained device with garbage collection then you’re probably familiar with with the Flyweight pattern or why it helps to avoid garbage collection. After a while you may have also noticed your program started to resemble a C like program where you obsess over releasing objects to some sort of pool and count memory like a tax collector counts… err.. uh… tax stuff. Bad analogies aside, the closer you get to C the better your software runs on both embedded and on servers.

So that’s why I’m sort of excited. I want to get closer to C and C++11 allows me to do that while providing many of the high level constructs I’ve grown familiar with over the years like literal collection initializers and the new “auto” keyword, and a decent Thread model. I’m getting ahead of myself, however. I’ve barely completed “Hello Bandit world!” I still have a lot to learn but it’s all looking gravy already.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s