MacPorts After Mavericks

You’ve finally upgraded your Macbook pro to Mavericks. Sure the other kids have been slinging the fancy new OS for a while now but you’ve been a straggler. You wanted to make sure the water was indeed safe before toe dipping. Maybe you’re just cautious, maybe you’ve been down this road before and bitten. Whatever the case, hey there! I’m Cliff. You’re here because one of your command line tools suddenly stopped working. I’m here because I just fixed it for you. Read on to find out what you should do after taking on Mavericks on your trusty silver laptop.

Say you’ve typed the name of a command you were using last month which was called… oh I dunno, asciidoc. Go ahead, say it… right now, audibly. I’ll wait… Did you say it? Of course you didn’t because that would be a ridiculous thing to do, especially at X o’clock during your work day/personal time after performing the Google search which landed you on this page.  Here you are just looking for an answer to why your command line isn’t giving you the respect that Aretha Franklin demanded back in 1967 and here I go sitting on standby waiting for you to make a goon of yourself by speaking out loud to absolutely nobody. We could go on like this for ages or I could just get to the point and say what I set out to say. Now what was I saying??? Oh, right! Say you have just typed the name of… [wait I already said that] say you just typed asciidoc into your terminal and say the terminal was like, “Whaaa? I don’t understand your French, cousin!” Now why would your terminal respond that way? I mean it’s not like you are actually related to the terminal or anything. It’s just a program, rather a collection of 1s and 0s spinning on your magnetic disk… unless you have a solid state drive. (Don’t most people have SSDs these days?) Then for you and these 1s and 0s to be actual cousins would mean that your parents were somehow siblings and since the parent of most computer programs is some hacker with bad hygiene one might assume his siblings have similar hygiene problems which, though possible, would lessen the probability of pro-creation leading to your birth.

I had a point somewhere about one or two sentences back but now I’m a bit lost. Where was I? Something about your terminal acting all confused like, “whaaa…?” wasn’t it? Okay, now say your terminal was like “whaaa…?” and you were all like, “you know, ‘asciidoc’!! Now gimme my converted output!” And then the terminal was still like “whaaaa…?” How does this happen? I mean, you were just speaking “asciidoc” in all of its PDF flavors a month ago and now it’s like your terminal doesn’t even know you despite the fact that it refers to you as a cousin, implying some sort of biological relation. It just doesn’t make sense… your binary flesh and blood acting like a random citizen from another country. Here’s where it all went wrong.

Mavericks Upgrade

After upgrading to Mavericks software installed with MacPorts stops behaving. The simple solution is to reinstall MacPorts. The best way to do this is to run “Xcode-select –install” from your terminal which will trigger an install/update of the Xcode Command line tools. This is important because MacPorts still thinks the tools it used before the upgrade (like /usr/bin/gnutar) are available. After reinstalling the tools you should reinstall MacPorts using the binary package which will see the upgraded command line tools. Read how to migrate MacPorts here. After upgrading your command line tools and reinstalling MacPorts you and your terminal will be on speaking terms again. Thanks for stopping to read my foolishness and remember to tip your waiter… because if you don’t tip then the waiter leaves nasty stuff in your food and stuff. That nasty stuff leads to diseases like foot and hand-mouth disease. I don’t know if that’s a real disease or not, its something that my father in law complained to my wife about when she was younger. She’s older now and has never caught foot and hand-mouth because she leaves nice tips. The waiters sometimes smile at her too, though I don’t necessarily think it’s because of the tips. I think they smile at her because she has a nice smile. Speaking of her smile, don’t forget to run your system updates after the Mavericks upgrade because apple has other fixes for you. I don’t really know what that has to do with my wife’s smile. It seemed related when I first typed it but now it just looks silly. My whole post is silly and probably hasn’t helped anyone. I’m rambling because I’m on my 3rd cup of coffee today. I should just stop typing now. Did you tip your waiter? I’m just sayin’…

Learning Android Gradle Unit Testing

The Gradle build system is pretty robust and it is becoming mainstream. That means it behooves you to start putting it to use. I’d been spending a little time with various Gradle based projects and realized that there were a couple of things missing… documentation on the Android plugin. Sure you can look here but I’m a rebel and I like to pretend there isn’t any documentation while learning the hard way. Hi, I’m Cliff. You’re here because you don’t read documentation. I’m here to show you how to reverse engineer your own documentation using Gradle/Groovy goodness. Today’s article is going to be short since it only covers a small area.

So I’m playing with a Gradle based Android project trying to get unit testing to work when I hit a snag. I had been so used to Maven and following all of the popular Gradle documentation online will have you believing, “Hey this works mostly like Maven!” In fact, a basic Java Gradle project is mostly indistinguishable from a Java Maven project from the outset in that they both follow the same familiar structure. Just drop your compile files into “src/main/java” and your test stuff into “src/main/test”. You hardly have to write any code in your build file to work with these types of projects. So it is almost a given that I get lost when I opened my new Gradle-based Android project and tried to add unit tests. Let’s start from my first sign of trouble in Android Studio. My initial step was to create a test folder for my project to begin adding tests to. Doing so I noticed it was colored manilla-tan and not green as I’d expected. Now in IntelliJ there’s a nice little right-mouse context menu that allows you to mark a folder as either a source directory, a test directory or a resource directory. Right clicking in Andoird Studio did not reveal the same feature so I thought there was a bug in the recent Canary update. (“Doggone Canary bleeding edge!”, is what I murmured to myself in disgust.) Then I thought I could just edit my Gradle build file to get the proper color on my folder allowing me to right click tests and run them directly.

I copied a source set config from an earlier Ant-based Android project that I coerced into Gradle. In this project I used the sourceSet configs to map the legacy Android-Ant structure into something Gradle could work with. This was done many months ago and several changes to Gradle and Android has happened since then but I figured it would still work the same since the original project was still functional. Dropping the following under the android config in my build.gradle did not change the color:

sourceSets {
    test {
        java.srcDirs = ['src/test/java']

Out of frustration I poured through all the Gradle documentation I had. Unfortunately I was reading Gradle docs and not Android plug docs for Gradle so I was confused into thinking what I was doing should work. Just before complaining on StackOverflow or filing a bug report I found a little hack I could use to debug my build.gradle. Remembering that a Gradle build is just Groovy source code gave me relief as I could just drop a println anywhere and inspect build elements in my console. (I use the terminal plugin in Android Studio so I didn’t even have to leave myIDE to try it.) I looked up the SourceSet API and then coded the following:

android.sourceSets.each {
    println "Sourceset: ${} java source: ${( ?':'):'Null')}"

That’s when it became apparent that there is not test source set in the Android plugin, only an androidTest sourceSet! I also learned, as I had figured, that there was no need to code an explicit source set so long as I followed whatever the convention was. I finally decided to write this blog post out of frustration because NOWHERE IN THE INTERNET UNIVERSE IS THERE ANY DOCUMENTATION EXPLAINING WHERE ANDROID TEST SOURCE LIVES!!! HOw frustrating it is to be an Android developer these days!

Native Android Development Part 1

I’ve ben spending the wee hours trying to grok native development on Android. NowI plan to spend my remaining hours trying to figure out what the difference between a “wee hour” and a regular hour is. I mean, c’mon… where does one find a “wee hour”? Is it a unit of time tracked by those under age 6 or those of diminutive stature? Am I being a baby just for bringing up this confusing point? I digress. I’m Cliff. You’re here because you’ve also spent some of your wee hours trying to understand the NDK, which is likely another black art. I’m here because I’m slowly understanding more pieces of it each day and have finally grown comfortable enough with what I know to attempt to share knowledge with you. Welcome to my world. Don’t get excited over the title, I don’t plan on making this into a series or anything. Any further articles which are consecutively numbered and related are by pure coincidence and not planned.

NDK Unit Testing

This week I am trying to tackle unit testing with the NDK. (Check back later for tips on how to build NDK apps with Gradle in Android studio!) For those who don’t know, the Android NDK ships with a number of unadvertised and hidden gems. Among those are docs, sources, samples, and a C++ unit test framework named GoogleTest. Some of you may recognize GoogleTest from other projects. I tripped over it while scouring the web looking for a suitable testing library for C/C++ and later discovered that not only can you download it from Google and build it for Android, but that it is now included with the latest NDK tools. Before I get distracted or sign off let me include the following tidbit (feel free to skip to the next bolded section since I haven’t explained the details yet):

If you are building GoogleTest, or guest as the fellas on the street call it, make sure you link to a C runtime that includes STL. More specifically, put something like this in your

APP_STL := stlport_static

If you’re doing something advanced, like using more than one native library in your app then you might want to read deeper and understand what it means to static link an STL runtime to your app. It might make sense to link the runtime dynamically instead because if you link more than one STL you get, like, in lots of trouble and stuff. So your code might want to look like this instead:

APP_STL := stlport_static

Lastly, if you are building either gtest or your native library with a non-standard structure you will need to point “ndk-build” to your file that includes the above magic code. There is a command line flag to tell “ndk-build” where to find it.

ndk-build NDK_APPLICATION_MK=path/to/

If you don’t understand any of the above just hold tight and I’ll eventually explain it all later on. Just know that this is something that you will need to do at some point.

Running CPP Unit tests without an apk
I am excited about this feature because, to date, I have been testing my JNI code through Java using the Android JUnit framework. GoogleTest allows you to run CPP unit tests against a .so native library without bundling it with a “.apk” and without the overhead of calling into it from Java. It makes tests run faster, it allows for quicker development of tests, and overall speeds everything up by removing a layer from each iteration. The quickest way to see all of this work is to follow the tutorial below which uses Google’s only sample code.

Copy the framework and samples from ${NDK_HOME}/sources/third_party into any folder of your choosing.
Create an file which links in STL support as a static library. Use the something like the following:

APP_PLATFORM := android-9
APP_STL := stlport_static
APP_CPPFLAGS := -fno-rtti

Build all source using the NDK:

~/android-ndk-r9d/ndk-build NDK_PROJECT_PATH=./ APP_BUILD_SCRIPT=./ NDK_APPLICATION_MK=./

This should generate a bunch of executables and one .so under libs/armeabi/ which need to be pushed to the device. Push them to the device using the following:

for eachFile in `ls libs/armeabi/`; do adb push libs/armeabi/$eachFile /data/local/tmp; done

Run all of the tests on your device

adb shell "LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/gtest_all_test"

Multiple symbol definitions

I found a way to allow multiple symbol definitions in a static library assembled from a bunch of object (.o) files. The secret sauce is adding “-z muldefs” to the g++ command line. I’m not sure what it tickles in the linker but it made my pains go away. One of these days I’ll spend a weekend playing with “ld” to see what other magic I can come up with.

Android device automation with ADB

Today’s post is something that could be a time saver or a reference for those are are vaguely familiar with Android automation. I’m posting because its something I keep coming across and something I hate having to lookup. Let’s call it…

“How to automate your Android device”

The “adb shell input” command can be used to automate any attached Android device by sending simple commands and input over USB. The syntax is:

input [<source>] <command> [<arg>…]

The sources are:

The commands and default sources are:
text <string> (Default: touchscreen) [delay]
keyevent [–longpress] <key code number or name> … (Default: keyboard)
tap <x> <y> (Default: touchscreen)
swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
press (Default: trackball)
roll <dx> <dy> (Default: trackball)

You can send key codes as input events using “adb shell input key event <keycode>” using the following list of key codes:

1 -->  "KEYCODE_MENU" 
3 -->  "KEYCODE_HOME" 
4 -->  "KEYCODE_BACK" 
5 -->  "KEYCODE_CALL" 
7 -->  "KEYCODE_0" 
8 -->  "KEYCODE_1" 
9 -->  "KEYCODE_2" 
10 -->  "KEYCODE_3" 
11 -->  "KEYCODE_4" 
12 -->  "KEYCODE_5" 
13 -->  "KEYCODE_6" 
14 -->  "KEYCODE_7" 
15 -->  "KEYCODE_8" 
16 -->  "KEYCODE_9" 
17 -->  "KEYCODE_STAR" 
18 -->  "KEYCODE_POUND" 
19 -->  "KEYCODE_DPAD_UP" 
26 -->  "KEYCODE_POWER" 
28 -->  "KEYCODE_CLEAR" 
29 -->  "KEYCODE_A" 
30 -->  "KEYCODE_B" 
31 -->  "KEYCODE_C" 
32 -->  "KEYCODE_D" 
33 -->  "KEYCODE_E" 
34 -->  "KEYCODE_F" 
35 -->  "KEYCODE_G" 
36 -->  "KEYCODE_H" 
37 -->  "KEYCODE_I" 
38 -->  "KEYCODE_J" 
39 -->  "KEYCODE_K" 
40 -->  "KEYCODE_L" 
41 -->  "KEYCODE_M" 
42 -->  "KEYCODE_N" 
43 -->  "KEYCODE_O" 
44 -->  "KEYCODE_P" 
45 -->  "KEYCODE_Q" 
46 -->  "KEYCODE_R" 
47 -->  "KEYCODE_S" 
48 -->  "KEYCODE_T" 
49 -->  "KEYCODE_U" 
50 -->  "KEYCODE_V" 
51 -->  "KEYCODE_W" 
52 -->  "KEYCODE_X" 
53 -->  "KEYCODE_Y" 
54 -->  "KEYCODE_Z" 
55 -->  "KEYCODE_COMMA" 
61 -->  "KEYCODE_TAB" 
62 -->  "KEYCODE_SPACE" 
63 -->  "KEYCODE_SYM" 
66 -->  "KEYCODE_ENTER" 
67 -->  "KEYCODE_DEL" 
68 -->  "KEYCODE_GRAVE" 
69 -->  "KEYCODE_MINUS" 
76 -->  "KEYCODE_SLASH" 
77 -->  "KEYCODE_AT" 
78 -->  "KEYCODE_NUM" 
80 -->  "KEYCODE_FOCUS" 
81 -->  "KEYCODE_PLUS" 
82 -->  "KEYCODE_MENU" 

Here are some common use cases.

Send an upward swipe gesture to the screen:
adb shell input swipe 200 900 200 300

Simulate pressing the back key
adb shell input keyevent 4

And for something more involved, log into Skype on an Android Motorola G smartphone using your Microsoft credentials

#tap the Microsoft log in button
adb shell input tap 80 622
#tap username
adb shell input tap 200 622
adb shell input text
#swipe to dismiss keypad
adb shell input tap 200 472
#tap password
adb shell input tap 200 900
adb shell input text password
#send enter key
adb shell input keyevent 66

Yak Shaving with the IntelliJ 13 SQL Query Plugin

My 9 year old daughter wanted to play a Pokemon battle with me this afternoon. I started to tell her, “I’ll be right there after I finish shaving this yak…” I’m sure folks would pay good money to see the confused look on her face if I were to have actually said that. Hi, I’m Cliff. You’re here because you shave yaks for a living. I’m here because I just finished vacuuming about 200 lbs of yak hair from my kitchen floor.

Pokemon Battle

Pokemon Battle

What in the world are you yaking about?

If you’re as late to the latest tech jargon that came out lately as I am then you probably never heard of the saying. Yak shaving is a term, which I recently heard/learned on the last few Hanselminutes podcasts. (If you haven’t heard of Scott Hanselman yet, check him out.) It was actually coined by Carlin Vieri in his time at the MIT AI Lab (1993-8) after viewing a 1991 episode of The Ren and Stimpy Show featuring “Yak Shaving Day,” a Christmas-like Holiday where participants hang diapers instead of stockings, stuff rubber boots with cole slaw, and watch for the shaven yak to float by in his enchanted canoe. It refers to the “meta-tasks” that you have to complete before you continue the real work you set out to do. An example would be if you were to write an iPhone app for a friend in an attempt to become the next Instagram. Your friend would likely come to you within a week to ask how’s the app coming along. You would likely reply, “I’ve registered for my developer account, downloaded the SDK, and I’m searching the forums while I try to resolve this provisioning profile issue I have on my iPad because it’s registered under multiple accounts.” It’s pretty common to start a mobile app this way having half a week go by without having written one line of code. So in essence you’re “shaving a yak” when you should be plotting UI components in Xcode’s StoryBoard.

About my Yak
I was busy processing some financial spreadsheets with Groovy scripts trying to load them in an instance of the Java embedded Derby Database when I ran into several issues. First, I couldn’t remember all of the SQL commands and Groovy stuff I used to use over 10 years ago when I was heavy into database number crunching. I went on a minor tangent to learn how to setup Derby, re-learn the GDK, prepared statements, etc. Next I needed to verify my data was being loaded correctly. The Derby ij command line interface was frustrating me so I decided to install a SQL plugin in IntelliJ. The most popular one, DB Navigator, wouldn’t work with my Derby db so I found the other more popular plugin… SQL Query. This plugin almost worked but it wouldn’t let me add a custom driver as there was an API change.

com.intellij.openapi.fileChooser.FileChooser.chooseFiles nosuchmethod

I Googled the error and found a hit on the Atlassian Clover plugin which had apparently fixed the same API change. While trying to find the diff in there plugin source I had to remember how I back-track bug fixes in Jira at work. I quickly realized that Clover was not open source so I investigated another hit and found the actual one-liner that fixes the error. I then needed to find the most recent copy of the SQL Query plugin source. After downloading I had to learn how to write Idea plugins, a topic which is well documented but still takes effort/practice. Along the way I ended up checking out the entire source for Idea as part of the plugin development setup instructions. (Have I ever mentioned how much I hate downloading excessive source?) I fought with dependency issues in the plugin itself as half of its dependencies were bundled as src jars and the other half was not included. Long story lengthened, I hacked the build.xml, downloaded the necessary dependencies, setup run/debug configs, uninstalled my existing SQL Query plugin to avoid potential conflicts (I don’t think it was necessary but just to be safe…) flushed the toilet several times, almost choked on a cup of coffee. In the end I managed to get both my data loaded into Derby and a working plugin that I can use to visualize the data in my IDE.

If I had just one more hour to spare I would format the above paragraph in the shape of a yak but I think you get my point. I feel awkwardly proud of myself, yet also disappointed. On the one hand I learned/compiled/debugged/built my 1st modified IntelliJ Idea plugin and I did it all in about an hour or two. I notified the original author and emailed him my updates. I will also have a pretty decent blog article documenting my experience. On the other hand half the day is gone and I only have one database table loaded and no understanding of the data I set out to mine. Still I am proud having self served my plugin error. It is a rewarding feeling to be on the development side of a fix where I’m usually begging the author, “please could you fix this error? It happens when I click here.” That sort of pleading is usually accompanied with arduous IDE log files, stripped-down or recoded pieces of whatever project I’m working on to preserve IP, frustration and an awkward smile when the author replies with, “could you send me the OTHER log files and which version of the thing are you running?”

Bash Hackery

This morning I found myself playing with bash commands trying to move a bunch of dirtied files to a Subversion change list. Most people find themselves after searching for years in college, others find themselves after volunteering for a mission or going on a trip to another country. Not me, I find myself in the middle of an iTerm session trying to make sense of a bunch of text files that have been dirtied (modified) by an improperly factored project structure after running a build which doesn’t restrict its output to one path. Hi, I’m Cliff. You’re here because you’d like to make sense of a bunch of files on your hard drive. Maybe you’re in a situation similar to mine. Maybe you just like hacking with shell commands, piping the output of one command into the input of another. I’m here to explain what I learned this morning.

I was frustrated because “svn st” kept spewing out a bunch of modified files for my project and I hadn’t made source changes. I modified some setting in Eclipse to get things to compile but that was the extent. I use change lists in IntelliJ all the time and I know you can do the equivalent from the command line using Subversion. So I get to hacking with awk and grep and paste to try and make sense of “svn st” output. Here’s what I came up with.

svn st
(Lists all modified files, but you probably already knew that.)
? .idea/scopes
? .idea/workspace.xml
? atlassian-ide-plugin.xml
? out
? awesome-android-ad-api/bin
M awesome-android-app/.classpath
? awesome-android-app/build/retrieve-ivy.xml
? awesome-android-app/libs/awesome-android-ad-api.jar
? awesome-android-app/libs/awesome-android-ad-impl.jar
? awesome-android-app/lint-report-formatted.xml
? awesome-android-app/lint-report.html
? awesome-android-app/lint-report.xml
M awesome-android-app/.classpath
M thirdparty/XPartyManagedView/lib/.classpath
M thirdparty/HockeySDK-Android/.classpath

svn st | grep -e ‘.classpath’
(list only ‘.classpath’ project files modified, this filters my output for the changes I made in my Eclipse settings.)
M awesome-android-app/.classpath
M thirdparty/XPartyManagedView/lib/.classpath
M thirdparty/HockeySDK-Android/.classpath

svn st | grep -e ‘.classpath’ | awk ‘{print($2);}’
(Print only the 2nd column from the earlier svn output which we filtered with grep. It’s pretty cool because now we’re getting to the actual files we want to operate on.)

paste -d ‘ ‘ -s <(svn st | grep -e '.classpath' | awk '{print($2);}')
(Flatten the one column output above listing only the file names into a single line delimited with a single space ‘ ‘ character. This is even better because now all of the files can be passed as a parameter to a shell command but how do we do that?)
awesome-android-app/.classpath thirdparty/XPartyManagedView/lib/.classpath thirdparty/HockeySDK-Android/.classpath

svn changelist “‘Eclipse project modifications.'” `paste -d ‘ ‘ -s <(svn st | grep -e '.classpath' | awk '{print($2);}')`
(We use back ticks “`” to return the value of our piped command chain as a parameter to the svn change list command and viola!)
A ['Eclipse project modifications.'] awesome-android-app/.classpath
A ['Eclipse project modifications.'] thirdparty/XPartyManagedView/lib/.classpath
A ['Eclipse project modifications.'] thirdparty/HockeySDK-Android/.classpath

All thanks to the magic of grep and awk. You can do all kinds of magic by chaining awk to grep to see and piping into past or whatever combination your mind can imagine. It just takes a little patience to familiarize with the command line flags and things like regex. Once you get the hang of it you’ll be flying…

Mac Automator tip of the day

So I was looking in TextMate for one of my most favorite tools from IntelliJ. It’s the “Compare with clipboard” action that takes whatever you have selected and runs a side-by-side diff with whatever is on your clipboard. I thought for sure it would exist in TextMate but I was disappointed so I built my own using Automator. See the pic below for the entire source. (There’s gotta be a better way to share Automator source but I’m in a hurry and lazy so there ya’ go.) This workflow depends on Xcode’s FileMerge but you can substitute whatever diff tool you’re comfortable with. To create it, start Automator and select System service from the “New…” action then copy in the actions from the image. Name it “Compare selection with clipboard” and then where ever you are in your Mac you will have access to the tool from the context menu (right clicking) of any selection.

Automator workflow

Compare selection with clipboard

When I first posted this there was a small bug. I changed the get clipboard step to an Applescript command “get the clipboard” since the built-in Automator task returns styled text instead of raw text.

Build a better mousetrap (Chat apps)

I’ve been quietly working on a chat app. I built one a long time ago which has been sitting on Github forever without any updates, but I’ve also recently pushed my Android “how to” to Github, you can find it here. I love working in both the Android and iOS space as I get a unique insight that I try to share with others. I also like to compare both the development process and tooling across both platforms. Hi, I’m Cliff. You’re here because you want to build a better chat app. I’m here for much the same reason. With apps like Skype, Line, whatsapp, and others crowding the space you might wonder “what’s the point?” I’m embarking on this experience partly to familiarize myself with what’s changed in iOS 7 but mainly just because. Maybe it will turn into something or maybe it won’t.

I’m my latest effort I’ve actually tried updating Jinx to support iOS7. My first stage has begun with introducing Storyboards and playing with Autolayout. I will later ARC-ify it and rip out the dumb artificial intelligence in favor of what I have in the Android example. Finally I want to incorporate P2P networking, voice recognition and TTS in both apps but that will have to wait until I hit the lottery and can afford to quit my job. (I’m just brimming with ideas!) If you have ideas or insights, feel free to jump in!

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.


Get every new post delivered to your Inbox.

Join 250 other followers